clear all
set more off
cap log close
set matsize 10000
/*------------------------------------------------------------------------------
Project: 		Schedule-Drive Productivity: Evidence from Non-Traditional School Calendars
				Taylor Landon and Nolan Pope

				This file creates the final analysis dataset and produces all of the tables and figures of the paper
*-------------------------------------------------------------------------------*/

*---------------------------------------------------------
* Set-up
*---------------------------------------------------------
cd "$project_location"

*** Globals used throughout paper ***
global outcomes zcstmath zcstela absent_frac repeat_grade dropout
global outcomes_limited dropout

global controls1 
global controls2 lagzmath lagzeng
global controls3 lagzmath lagzeng ell lagsuspend lagabsent_frac lagzmath_avg_without lagzeng_avg_without frac_asian frac_hisp frac_black frac_white frac_frelch frac_redlch member member2 studteacher_ratio
global controls4 frac_asian frac_hisp frac_black frac_white frac_frelch frac_redlch member member2 studteacher_ratio

	
global controls_eventStudy frac_asian frac_hisp frac_black frac_white frac_frelch frac_redlch member member2 studteacher_ratio
	

* Used for Teacher Turnover
global outcomes_teacher leftschool inexp_leave exp_leave

global controlsTeacher1
global controlsTeacher2 l_sgela l_sgmath
global controlsTeacher3 l_sgela l_sgmath frac_asian frac_hisp frac_black frac_white frac_frelch frac_redlch member member2 studteacher_ratio
global controlsTeacher4 frac_asian frac_hisp frac_black frac_white frac_frelch frac_redlch member member2 studteacher_ratio
	
* Used for EVent Study
global base -1

*---------------------------------------------------------
* Prepare Common Core and LAUSD calendar datasets
*---------------------------------------------------------
*** Average statistics about each school from the Common Core of Data from the National Center for Education Statsistics (https://nces.ed.gov/ccd/ccddata.asp)
do "$data/clean_ccd.do" // Cleans ccd data

*** We obtain school calendar type from the LAUSD website using the Wayback Machine. 
do "$data/clean_calendar_files.do" // Prepares calendar data

** Merge all datasets using cdscode
*---------------------------------------------------------
* Determine which, how, and when schools switch
*---------------------------------------------------------
use "data_yearlong/LAUSD_compiled.dta", clear  // CCD, and LAUSD school-level calendar data

// Single-track calendars also have the cal_custom dummy (i.e. they follow a custom schedule.)
// Multi-track calendars either have a 90-30 or a concept 6 calendar.

replace cal_single = 0 if cal_trad == 1 & cal_single == 1
egen school_id = group(cdscode)

duplicates drop school_id year cal_trad cal_single cal_mult cal_60_20 ///
	cal_60_15 cal_90_30 cal_45_15 cal_concept6 cal_modified cal_custom, force

drop cal_60_20 cal_60_15 cal_45_15 cal_modified  // very few in these categories
	

// Nexts parts determine if schools switch, and if so, to and from
// I do it for each calendar type

* to and from Traditional calendars
bysort school_id (year): gen switch_totrad = 1 if cal_trad[_n] != cal_trad[_n-1] ///
	& !missing(cal_trad[_n-1]) ///
	& cal_trad[_n] == 1 & cal_trad[_n-1] == 0

bysort school_id (year): gen switch_fromtrad = 1 if cal_trad[_n] != cal_trad[_n-1] ///
	& !missing(cal_trad[_n-1]) ///
	& cal_trad[_n] == 0 & cal_trad[_n-1] == 1

bysort school_id (year): egen total_switch1 = sum(switch_totrad)
bysort school_id (year): egen total_switch2 = sum(switch_fromtrad)

bysort school_id (year): gen total_switch_trad = total_switch1 + total_switch2
drop total_switch1 total_switch2


* to and from Single-track calendars
bysort school_id (year): gen switch_tosing = 1 if cal_single[_n] != cal_single[_n-1] ///
	& !missing(cal_single[_n-1]) ///
	& cal_single[_n] == 1 & cal_single[_n-1] == 0

bysort school_id (year): gen switch_fromsing = 1 if cal_single[_n] != cal_single[_n-1] ///
	& !missing(cal_single[_n-1]) ///
	& cal_single[_n] == 0 & cal_single[_n-1] == 1

bysort school_id (year): egen total_switch1 = sum(switch_tosing)
bysort school_id (year): egen total_switch2 = sum(switch_fromsing)

bysort school_id (year): gen total_switch_sing = total_switch1 + total_switch2
drop total_switch1 total_switch2


* to and from Multi-track calendars
bysort school_id (year): gen switch_tomult = 1 if cal_mult[_n] != cal_mult[_n-1] ///
	& !missing(cal_mult[_n-1]) ///
	& cal_mult[_n] == 1 & cal_mult[_n-1] == 0

bysort school_id (year): gen switch_frommult = 1 if cal_mult[_n] != cal_mult[_n-1] ///
	& !missing(cal_mult[_n-1]) ///
	& cal_mult[_n] == 0 & cal_mult[_n-1] == 1

bysort school_id (year): egen total_switch1 = sum(switch_tomult)
bysort school_id (year): egen total_switch2 = sum(switch_frommult)

bysort school_id (year): gen total_switch_mult = total_switch1 + total_switch2
drop total_switch1 total_switch2


* Schools that do not change calendar
bysort school_id (year): ///
	gen no_cal_changes = (total_switch_trad + total_switch_sing + total_switch_mult == 0)


* Define a Transition from trad to another
gen trad2sing = 1 if switch_fromtrad ==1 & switch_tosing == 1
gen trad2mult = 1 if switch_fromtrad ==1 & switch_tomult == 1

* Define a Transition from single to another
gen sing2trad = 1 if switch_totrad ==1 & switch_fromsing == 1
gen sing2mult = 1 if switch_tomult ==1 & switch_frommult == 1	
		

* Define a Transition from multi to another
gen mult2sing = 1 if switch_frommult ==1 & switch_tosing == 1	
gen mult2trad = 1 if switch_frommult ==1 & switch_totrad == 1			


* creates vars for year change occurs and how many cal changes a school makes
gen yearOfChange = year if trad2sing == 1 | trad2mult == 1 | sing2trad == 1 | ///
	sing2mult == 1 | mult2sing == 1 | mult2trad == 1

gen numberOfChanges = 0 if no_cal_changes == 1
replace numberOfChanges = 1 if total_switch_trad == 1 | total_switch_sing == 1 | ///
	total_switch_mult == 1

replace numberOfChanges = 2 if total_switch_trad == 2 | total_switch_sing == 2 | ///
	total_switch_mult == 2
	
replace numberOfChanges = 3 if total_switch_trad == 3 | total_switch_sing == 3 | ///
	total_switch_mult == 3
	
replace numberOfChanges = 4 if total_switch_trad == 4 | total_switch_sing == 4 | ///
	total_switch_mult == 4

order school_id year total_switch* no_cal_changes trad2* sing2* mult2* yearOfChange

save "$data/schools_by_year.dta", replace


*---------------------------------------------------------
* Attach school treatment data to student level data
*---------------------------------------------------------
use "$data/schools_by_year.dta", replace
xtset, clear

tempfile treated_schools
keep if numberOfChanges == 1 | numberOfChanges == 0 // small number changes calendar types multiple times
gen ever_treated = numberOfChanges
order school_id year ever_treated total_switch* no_cal_changes trad2* sing2* mult2* yearOfChange


gen switch_type = 0 if numberOfChanges == 0  // trad only
replace switch_type = 1 if total_switch_mult == 1 // Transition from 90-30 or c6 school
replace switch_type = 2 if total_switch_sing == 1 // Transition from single-track or custom

bysort school_id: egen yearChange = max(yearOfChange)

label define switch_type 0 "No Change" 1 "Multi to trad" 2 "Single to Trad"
label values switch_type switch_type

keep cdscode ever_treated switch_type yearChange numberOfChanges
duplicates drop 

save `treated_schools'


use "$data/LAUSD_DATA.dta", clear

drop if stdpseudoid < 100000 // multiple students assigned same ids under 100,000

merge m:1 cdscode using `treated_schools'  //attaches treated schools to main data
keep if _merge == 3 // 7,230,741 merged
drop _merge

egen student_id = group(stdpseudoid)
egen school_id = group(cdscode)

xtset student_id year

gen switch_treatment = 0
replace switch_treatment = 1 if year >= yearChange

gen trad = 1 
replace trad = 0 if year < yearChange & yearChange != .


egen school_by_year = group(school_id year)
egen grade_by_year = group(grade year)



//Determine elem, middle, or high school
bysort school_id year: egen level_a = mode(level), minmode
* 13 == Kindergarten

/*
From CCD - Level Variable
1 = Primary (low grade = PK through 03; high grade = PK through 08)
2 = Middle (low grade = 04 through 07; high grade = 04 through 09)
3 = High (low grade = 07 through 12; high grade = 12 only)
4 = Other (any other configuration not falling within the above three categories, including ungraded)
N = Not applicable
*/

* Middle == 5-8
* High == 9-12

gen level_temp = . 
replace level_temp = 1 if (((gsloa >= 1 & gsloa <= 3) | gsloa == 13) & ((gshia >= 1 & gshia <=8) | gshia == 13))
replace level_temp = 2 if ((gsloa >= 4 & gsloa <= 7) & (gshia >= 4 & gshia <=9))
replace level_temp = 3 if ((gsloa >= 7 & gsloa <= 12) & (gshia == 12))
replace level_temp = 4 if level_temp != 1 & level_temp != 2 & level_temp != 3

bysort school_id: egen level_b = mode(level_temp), minmode

drop level
gen level = level_b
drop level_*

tabulate level, generate(dummy_level)
rename dummy_level1 elem
rename dummy_level2 middle
rename dummy_level3 highschool
rename dummy_level4 custom

*** School characteristics each year and in the first year observed ***
bysort school_id (year): egen first_year_observed = min(year)

foreach var of varlist asian hisp black white frelch redlch totfrl{
	gen frac_`var' = `var'/member
	bysort school_id: gen `var'_firstyear1 = frac_`var' if year == first_year_observed
	bysort school_id: egen `var'_firstyear = min(`var'_firstyear1)
}

drop *_firstyear1

	label var elem "Elementary Schools"
	label var middle "Middle Schools"
	label var highschool "Highschools"
	label var custom "Not Elementary, Middle, or Highschool"
	label var frac_asian "Percent Students Asian"
	label var frac_hisp "Percent Students Hispanic"
	label var frac_black "Percent Students Black"
	label var frac_white "Percent Students White"
	label var frac_frelch "Percent Free Lunch Eligible"
	label var frac_redlch "Percent Reduced-price Lunch Eligible"
	label var frac_totfrl "Percent Free or Reduced Lunch"
	label var asian_firstyear "First Year - Percent Asian"
	label var hisp_firstyear "First Year - Percent Hisp"
	label var black_firstyear "First Year - Percent Black"
	label var white_firstyear "First Year - Percent White"
	label var frelch_firstyear "First Year - Percent Free Lunch"
	label var redlch_firstyear "First Year - Percent Reduced Lunch"
	label var totfrl_firstyear "First Year - Percent Free or Reduced Lunch"
	

bysort school_id: egen concept6_school = max(cal_concept6)
gen cohort = year - grade
gen time = year - yearChange

gen after2009 = (yearChange >= 2010)
gen after2008 = (yearChange >= 2009)

// Control group 1: Concept 6 school before 2008 compared to those after 2008
gen control1 = 0 if ever_treated == 1 & concept6_school == 1 & after2008 == 0
replace control1 = 1 if ever_treated == 1 & concept6_school == 1 & after2008 == 1

// Control group 2: 90-30 schools before 2008 compared to those after 2008	
gen control2 = 0 if ever_treated == 1 & concept6_school == 0 & after2008 == 0
replace control2 = 1 if ever_treated == 1 & concept6_school == 0 & after2008 == 1
	
// Control group 3: Concept6 and 90-30 schools compared to those that did not change calendar type
gen control3 = (ever_treated == 0)


// Student and school level controls
xtset student_id year
gen absent_frac = ytdabsentdaycnt/ytdenrolleddaycnt

replace dayssuspended = 0 if dayssuspended == . 
replace numofsuspendions = 0 if numofsuspendions == .


// Gen Lagged Variables
gen lagsuspend = l.dayssuspended
gen lagzmath = l.zcstmath
gen lagzeng = l.zcstela
gen lagmath = l.cstscoremath
gen lageng = l.cstscoreela
gen laggpa = l.gpatotal
gen lagabsent_frac = l.absent_frac
gen lagsuspend_dummy = (lagsuspend > 0 & lagsuspend != .)
replace lagsuspend_dummy = . if lagsuspend == .

// English Language learner
gen ell = (zceldtoverall != .)

// lagged school test scores
preserve

tempfile school_char

collapse (mean) zcstmath zcstela cstscoremath cstscoreela, by(school_id grade year)
pause

foreach var of varlist zcstmath zcstela cstscoremath cstscoreela{
	bysort school_id grade (year): gen lag`var'_schgrdavg = `var'[_n-1] if `var'[_n-1] != .
	rename `var' `var'_schgradavg
}

save `school_char'
restore

merge m:1 school_id year grade using `school_char'

* Leave one out lagged test scores
foreach var of varlist lagzmath lagzeng lagmath lageng{
	bysort school_id year grade: egen total_`var' = total(`var')
	by school_id year grade: egen year_count_`var' = count(`var')  
	gen `var'_avg_without = (total_`var' - cond(missing(`var'), 0, `var')) / (year_count_`var' - !missing(`var'))
}

drop total_* year_count_* _merge

// Additional variables
gen member2 = member^2
gen studteacher_ratio = member/fte

// Determine the type of calendar each school has each year
gen yrs_concept6 = 1 if ever_treated == 1 & year <= yearChange & concept6_school == 1
gen yrs_9030 = 1 if ever_treated == 1 & year <= yearChange & concept6_school == 0
gen yrs_trad = 1 if ever_treated == 0 | (ever_treated == 1 & year > yearChange) 

foreach var of varlist yrs_*{
	replace `var' = 0 if `var' == .
}

	
label var zcstela "Standardized English test scores"
label var zcstmath "Standardized math test scores"
label var absent_frac "Fraction of days absent"

drop if switch_type == 2 // Keep only trad and multi-track schools

// Change in test scores

foreach var of varlist zcstmath zcstela{
	bysort student_id (year): gen diff`var' = `var' - L.`var'
}


// Create Repeat Grade Variable
bysort student_id grade (year): gen repeat_grade1 = _n
gen repeat_grade = (repeat_grade1 > 1)



/*Create ever graduated variable 
	1 if graduated by the end of the data, 
	0 if not graduate by end of the data, 
	. if data is not available or does not reach 12th grade by last year of data
*/

bysort student_id: egen evergrad = total(graduated),missing 
replace evergrad = 1 if evergrad > 0 & evergrad < .
bysort student_id: egen maxgrade = max(grade)
bysort student_id: egen maxyear = max(year)
replace evergrad = . if maxgrade < 12 & evergrad == 0 

/*
Create outcome variable that is ever graduated 
	1 if graduated by the end of the data, 
	0 if did not graduated by end of the data and have reached grade 12
	. if data is not available or does not reach 12th grade by last year of data
*/

gen evergrad2 = 0
replace evergrad2 = evergrad if evergrad > 0 & evergrad < . 
replace evergrad2 = . if maxgrade < 12 & evergrad2 == 0 


// Sample Restriction
* keep if zcstela != . & zcstmath != .
* keep if grade >= 2 & grade <= 11
* drop if cohort <= 1992 | cohort > 2009
drop if grade > 12


bysort student_id (year grade): gen numOfYears = _N
label var numOfYears "Num of Yrs Student Obseved in data"

// Determine which type of schools students attended
bysort student_id: egen max_switch = max(switch_treatment)
bysort student_id: gen always_trad = (max_switch == 0)


bysort student_id: gen went_toc6 = 1 if switch_treatment == 1 & concept6_school == 1
bysort student_id: gen went_to9030 = 1 if switch_treatment == 1 & concept6_school == 0
bysort student_id: egen wenttoc6 = max(went_toc6)
bysort student_id: egen wentto9030 = max(went_to9030)

// drop observations that went to both 90-30 and c6 school; < 2%
bysort student_id: gen wenttoc6and9030 = (wenttoc6 + wentto9030 == 2)
drop if wenttoc6and9030 == 1

order student_id school_id grade year yearChange switch_treatment ever_treated ///
	zcstela zcstmath absent_frac repeat_grade evergrad ///
	fte member frelch redlch totfrl  ///
	asian hisp black white frac_* ///
	school_by_year grade_by_year *_firstyear ///
	elem middle highschool custom

bysort student_id (year): gen enrolled_9th = 1 if grade == 9
bysort student_id (year): egen enrolled_9_1 = min(enrolled_9th)

bysort student_id (year): egen max_grade = max(grade)

gen count = (grade >=9)
bysort student_id (year): egen count_years = total(count)

*** Create dropout allowing for 5 years to graduate
bysort student_id (year): gen dropout_temp = 1 if enrolled_9th == 1 & evergrad == 0 & year <= 2010
bysort student_id (year): egen dropout_temp2 = min(dropout_temp)
replace dropout_temp2 = 0 if enrolled_9th == 1 & evergrad == 1 & year <= 2011
bysort student_id (year): egen dropout = min(dropout_temp2)
drop dropout_temp dropout_temp2

drop if school_id == 196  // remains concept 6 school throughout period


*** Create low, middle, high type students based on math, english, and avg test scores
gen takes_test = (grade >= 2 & grade < 12)
bysort student_id takes_test (year grade): egen firstyear_std = min(year)
gen firstgrade_std = grade if firstyear_std == year



gen overall = (zcstela + zcstmath)/2
bysort firstyear_std firstgrade_std takes_test: egen p33_overall = pctile(overall) ///
	if firstyear_std == year & firstgrade_std == grade, p(33)
bysort firstyear_std firstgrade_std takes_test: egen p66_overall = pctile(overall) ///
	if firstyear_std == year & firstgrade_std == grade, p(66)

gen g_overall1 = 0 if overall <= p33_overall & overall != . & p33_overall != .
replace g_overall1 = 1 if overall > p33_overall & overall <= p66_overall & overall != . & p33_overall != . & p66_overall != .
replace g_overall1 = 2 if overall > p66_overall & overall != . & p66_overall != .

bysort student_id (year): egen g_overall = min(g_overall1)

drop g_overall1 p33_overall p66_overall takes_test firstyear_std firstgrade_std ///
	p33_overall p66_overall g_overall1
	

rename switch_treatment switch_treatment1
gen switch_treatment = 1
replace switch_treatment = 0 if year < yearChange & yearChange != .

keep if elem == 1 | middle == 1 | highschool == 1

replace elem = . if grade > 8 & elem == 1
replace middle = . if (grade > 8 | grade < 6) & middle == 1
replace highschool = . if grade < 9 & highschool == 1

compress

save "$data/main.dta", replace

*---------------------------------------------------------
* Prepare Teacher Turnover Data
*---------------------------------------------------------
use "$data/schools_by_year.dta", clear

keep cdscode school_id year trad yearChange concept6_school ///
	ever_treated fte member member2 frelch redlch totfrl asian hisp black white ///
	frac_asian frac_hisp frac_black frac_white frac_frelch frac_redlch ///
	frac_totfrl elem middle highschool studteacher_ratio ell
	

tempfile school_data
save `school_data'
	
	
use "$data/LAUSD_DATA.dta", clear
keep teacherid year cdscode
	bys teacherid cdscode year: keep if _n == 1
	
	*Drop blanks
	drop if teacherid == .
	
	*Generate new ID for teacher/school cell; then xtset
	egen teacherid2 = group(teacherid cdscode)	
	xtset teacherid2 year
	tsfill, full
	sort teacherid2 year
	
	*Generate attrition variable
	gen leftschool = .
	by teacherid2: replace leftschool = 1 if cdscode[_n+1]!=cdscode[_n] & cdscode != . 
	by teacherid2: replace leftschool = 0 if cdscode[_n+1]==cdscode[_n] & cdscode != .
	drop if teacherid == .
	
	*Generate experience variable
	by teacherid2: gen yearsteaching = _n - 1
	drop teacherid2
	
	
	
xtset, clear
replace year = year - 1

* Merge calendar data to teacher data
merge m:1 cdscode year using `school_data'
keep if _merge == 3

foreach var of varlist l_sgmath l_sgela{
	bysort school_id year grade: egen total_`var' = total(`var')
	by school_id year grade: egen year_count_`var' = count(`var')  
	gen `var'_avg_without = (total_`var' - cond(missing(`var'), 0, `var')) / (year_count_`var' - !missing(`var'))
}

bysort school_id year grade: egen class_lag = mean(l)
drop total_* year_count_* _merge

bysort teacherid school_id: egen max_yrsteaching = max(yearsteaching)

gen inexp_leave = leftschool if max_yrsteaching < 3
gen exp_leave = leftschool if max_yrsteaching  >= 3

egen grade_by_year1 = group(grade year)

bysort teacherid year school_id grade: egen biggest_class = max(nstudents)
gen choose = 1 if biggest_class == nstudents

gen fe = grade_by_year1 if choose == 1
bysort teacherid year: egen grade_by_year = min(fe)

bysort teacherid year (nstudents): gen num = _n

keep if num == 1

drop fe grade_by_year1 biggest_class choose

save "$main/teacher.dta", replace

*---------------------------------------------------------
* Figure 1 
*---------------------------------------------------------
* Created manually using LAUSD 2005 School Year Calendar Data

*---------------------------------------------------------
* Figure 2 Panel A: Schools Transitioned to the Trad Calendar 2003-2012
*---------------------------------------------------------
use "$data/schools_by_year.dta", clear

by school_id: egen concept6_school = max(cal_concept6)

keep if numberOfChanges == 1

collapse (sum) sing2trad mult2trad, by(year concept6_school)
reshape wide mult2trad sing2trad, i(year) j(concept6_school)

keep if year <= 2012
colorpalette lin brands, select(2 4 5 6) nograph

graph bar mult2trad1 mult2trad0, over(year) stack ///
	ytitle("Number of Schools") ///
	ylabel(, format(%12.0fc)) xsize(8) ///
	bar(1, fcolor("`r(p1)'") lcolor(black) lwidth(vvthin)) ///
	bar(2, fcolor("`r(p3)'") lcolor(black) lwidth(vvthin)) ///
	legend(lab(2 "90-30 to Traditional Calendars") lab(1 "Concept 6 to Traditional Calendars") rows(1) size(small) pos(6))

graph export "figures/changes_by_year.pdf", replace


*---------------------------------------------------------
* Figure 2 Panel b: Schools Transitioned to the Trad Calendar 2003-2012, C6 by school type
*---------------------------------------------------------
use "$data/schools_by_year.dta", clear

//Determine elem, middle, or high school
bysort school_id year: egen level_a = mode(level), minmode
* 13 == Kindergarten

/*
From CCD - Level Variable
1 = Primary (low grade = PK through 03; high grade = PK through 08)
2 = Middle (low grade = 04 through 07; high grade = 04 through 09)
3 = High (low grade = 07 through 12; high grade = 12 only)
4 = Other (any other configuration not falling within the above three categories, including ungraded)
N = Not applicable
*/

* Middle == 5-8
* High == 9-12

gen level_temp = . 
replace level_temp = 1 if (((gsloa >= 1 & gsloa <= 3) | gsloa == 13) & ((gshia >= 1 & gshia <=8) | gshia == 13))
replace level_temp = 2 if ((gsloa >= 4 & gsloa <= 7) & (gshia >= 4 & gshia <=9))
replace level_temp = 3 if ((gsloa >= 7 & gsloa <= 12) & (gshia == 12))
replace level_temp = 4 if level_temp != 1 & level_temp != 2 & level_temp != 3

bysort school_id: egen level_b = mode(level_temp), minmode

drop level
gen level = level_b
drop level_*

tabulate level, generate(dummy_level)
rename dummy_level1 elem
rename dummy_level2 middle
rename dummy_level3 highschool
rename dummy_level4 custom

by school_id: egen concept6_school = max(cal_concept6)
keep if concept6_school == 1

keep if numberOfChanges == 1

collapse (sum) mult2trad, by(year level)
reshape wide mult2trad, i(year) j(level)

keep if year <=2012
colorpalette lin brands, select(2 4 5 6) nograph

graph bar mult2trad1 mult2trad2 mult2trad3, over(year) stack ///
	ytitle("Number of Schools") ///
	ylabel(, format(%12.0fc)) xsize(8) ///
	bar(1, fcolor("`r(p1)'") lcolor(black) lwidth(vvthin)) ///
	bar(2, fcolor("`r(p3)'") lcolor(black) lwidth(vvthin)) ///
	bar(3, fcolor("`r(p2)'") lcolor(black) lwidth(vvthin)) ///
	legend(lab(1 "Elementary Schools") ///
	lab(2 "Middle Schools") ///
	lab(3 "High Schools") ///		
	rows(1) size(small) pos(6))

graph export "figures/changes_by_yearandtype.pdf", replace



*---------------------------------------------------------
* Figures 3-6: Dynamic Treatment Effects Acccounting for Potential Heterogeneous Treatment Effects
*---------------------------------------------------------

*** 90-30 schools ***
foreach outcome of global outcomes {
use "$data/main.dta"", clear

drop if concept6_school == 1 & ever_treated == 1 // Keep only 90-30 schools and those without cal changes
keep if elem == 1
	
	
label var zcstela "Standardized English Test Scores"
label var zcstmath "Standardized Math Test Scores"
label var absent_frac "Fraction of Days Absent"
label var repeat_grade "Probability of Repeating Grade"
label var dropout "Probability of Droppping Out"

local subtitle: variable label `outcome'


gen neverSwitch = (yearChange == .)	

egen minval = min(time)
egen maxval = max(time)
local minval = minval



forvalues k = `minval'(1)-2{
	local negk = -1*`k'
	gen w_`negk' = time == `k'
}
  
local maxval = maxval
forvalues k = 0/`maxval' {
	gen q_`k' = time == `k'
}

if "`outcome'" != "dropout"{
	display "Student"
	eventstudyinteract `outcome' w_* q_* , cohort(yearChange) control_cohort(neverSwitch) covariates($controls4) absorb(i.grade_by_year i.school_id i.student_id) vce(cluster school_id)

}

if "`outcome'" == "dropout"{
	display "Lagged"
	eventstudyinteract `outcome' w_* q_* , cohort(yearChange) control_cohort(neverSwitch) covariates($controls3) absorb(i.grade_by_year i.school_id) vce(cluster school_id)
}

	

			
matrix coef = e(b_iw)
mata st_matrix("A",sqrt(st_matrix("e(V_iw)")))
matrix coef = coef \ A
matrix coef = coef'
matrix list coef

svmat coef, names(sun)
keep sun*
drop if sun1 == .
rename sun1 coef
rename sun2 std_error
gen min95 = coef - 1.95996398454005423552*std_error
gen max95 = coef + 1.95996398454005423552*std_error

gen label = _n
replace label = label + `minval'
replace label = label - 1 if label <0
expand 2 if label == 0
bysort label: gen num = _n
replace label = -1 if num == 2
replace coef = 0 if num == 2
replace min95 = 0 if num ==2
replace max95 = 0 if num == 2

if "`outcome'" != "dropout"{
keep if label >= -5 & label <= 5

label variable coef "Point Estimate"
label variable min95 "lower 95% CI "
label variable max95 "upper 95% CI"

sort label
colorpalette lin brands, select(2 4 5 6) nograph
twoway (scatter coef label, mcolor("`r(p1)'") msymbol(0) msize(small)) ///
	(rcap max95 min95 label, lcolor(black)), ///
	xline(-1, lstyle(foreground)) ///
	yline(0, lcolor(red)) ///
	xlabel(-5(1)5) ///
	ytitle("`subtitle'") xsize(4.6) ///
	xtitle("Years Since School Transitioned to Traditional Calendar") ///
	legend(off)
	
graph export "figures/sun_`outcome'_9030.pdf", replace


}

if "`outcome'" == "dropout"{
keep if label >= -5 & label <= 2

label variable coef "Point Estimate"
label variable min95 "lower 95% CI "
label variable max95 "upper 95% CI"

sort label
colorpalette lin brands, select(2 4 5 6) nograph
twoway (scatter coef label, mcolor("`r(p1)'") msymbol(0) msize(small)) ///
	(rcap max95 min95 label, lcolor(black)), ///
	xline(-1, lstyle(foreground)) ///
	yline(0, lcolor(red)) ///
	xlabel(-5(1)2) ///
	ytitle("`subtitle'") xsize(4.6) ///
	xtitle("Years Since School Transitioned to Traditional Calendar") ///
	legend(off)
	
graph export "figures/sun_`outcome'_9030.pdf", replace


}



}

*** Concept 6 schools ***
foreach type in elem middle{
foreach outcome of global outcomes{
use "$data/main.dta"", clear

drop if concept6_school == 0 & ever_treated == 1 // Keep only concept 6 schools and those without cal changes
keep if `type' == 1


label var zcstela "Standardized English Test Scores"
label var zcstmath "Standardized Math Test Scores"
label var absent_frac "Fraction of Days Absent"
label var repeat_grade "Probability of Repeating Grade"
label var dropout "Probability of Droppping Out"

local subtitle: variable label `outcome'


gen neverSwitch = (yearChange == .)

egen minval = min(time)
egen maxval = max(time)
local minval = minval

forvalues k = `minval'(1)-2{
	local negk = -1*`k'
	gen w_`negk' = time == `k'
}
  
local maxval = maxval
forvalues k = 0/`maxval' {
	gen q_`k' = time == `k'
}


if "`outcome'" != "dropout"{
	eventstudyinteract `outcome' w_* q_* , cohort(yearChange) control_cohort(neverSwitch) covariates($controls4) absorb(i.grade_by_year i.school_id i.student_id) vce(cluster school_id)
}

if "`outcome'" == "dropout"{
	eventstudyinteract `outcome' w_* q_* , cohort(yearChange) control_cohort(neverSwitch) covariates($controls3) absorb(i.grade_by_year i.school_id) vce(cluster school_id)
}
			
matrix coef = e(b_iw)
mata st_matrix("A",sqrt(st_matrix("e(V_iw)")))
matrix coef = coef \ A
matrix coef = coef'
matrix list coef

svmat coef, names(sun)
keep sun*
drop if sun1 == .
rename sun1 coef
rename sun2 std_error
gen min95 = coef - 1.95996398454005423552*std_error
gen max95 = coef + 1.95996398454005423552*std_error

gen label = _n
replace label = label + `minval'
replace label = label - 1 if label < 0
expand 2 if label == 0
bysort label: gen num = _n
replace label = -1 if num == 2
replace coef = 0 if num == 2
replace min95 = 0 if num ==2
replace max95 = 0 if num == 2

label variable coef "Point Estimate"
label variable min95 "lower 95% CI "
label variable max95 " upper 95% CI"

if "`outcome'" != "dropout"{
keep if label >= -5 & label <= 5
}

if "`outcome'" == "dropout"{
keep if label >= -5 & label <= 3
}


sort label
colorpalette lin brands, select(2 4 5 6) nograph


twoway (scatter coef label, mcolor("`r(p1)'") msymbol(0) msize(small)) ///
	(rcap max95 min95 label, lcolor(black)), ///
	xline(-1, lstyle(foreground)) ///
	yline(0, lcolor(red)) ///
	ytitle("`subtitle'") xsize(4.6) ///
	xlabel(-5(1)5) ///
	xtitle("Years Since School Transitioned to Traditional Calendar") ///
	legend(off)
	
graph export "figures/sun_`outcome'_`type'.pdf", replace

}
}


foreach type in highschool{
foreach outcome of global outcomes{
use "$data/main.dta"", clear

drop if concept6_school == 0 & ever_treated == 1 // Keep only concept 6 schools and those without cal changes
keep if `type' == 1

label var zcstela "Standardized English Test Scores"
label var zcstmath "Standardized Math Test Scores"
label var absent_frac "Fraction of Days Absent"
label var repeat_grade "Probability of Repeating Grade"
label var dropout "Probability of Droppping Out"


local subtitle: variable label `outcome'


gen neverSwitch = (yearChange == .)

egen minval = min(time)
egen maxval = max(time)
local minval = minval

forvalues k = `minval'(1)-2{
	local negk = -1*`k'
	gen w_`negk' = time == `k'
}
  
local maxval = maxval
forvalues k = 0/`maxval' {
	gen q_`k' = time == `k'
}


	
if "`outcome'" != "dropout"{
	eventstudyinteract `outcome' w_* q_* , cohort(yearChange) control_cohort(neverSwitch) covariates($controls4) absorb(i.grade_by_year i.school_id i.student_id) vce(cluster school_id)
}

if "`outcome'" == "dropout"{
	eventstudyinteract `outcome' w_* q_* , cohort(yearChange) control_cohort(neverSwitch) covariates($controls3) absorb(i.grade_by_year i.school_id) vce(cluster school_id)
}
			
matrix coef = e(b_iw)
mata st_matrix("A",sqrt(st_matrix("e(V_iw)")))
matrix coef = coef \ A
matrix coef = coef'
matrix list coef

svmat coef, names(sun)
keep sun*
drop if sun1 == .
rename sun1 coef
rename sun2 std_error
gen min95 = coef - 1.95996398454005423552*std_error
gen max95 = coef + 1.95996398454005423552*std_error

gen label = _n
replace label = label + `minval'
replace label = label - 1 if label < 0
expand 2 if label == 0
bysort label: gen num = _n
replace label = -1 if num == 2
replace coef = 0 if num == 2
replace min95 = 0 if num ==2
replace max95 = 0 if num == 2

label variable coef "Point Estimate"
label variable min95 "lower 95% CI "
label variable max95 " upper 95% CI"

if "`outcome'" != "dropout"{
keep if label >= -5 & label <= 4
}

if "`outcome'" == "dropout"{
keep if label >= -5 & label <= 4
}


sort label
colorpalette lin brands, select(2 4 5 6) nograph


twoway (scatter coef label, mcolor("`r(p1)'") msymbol(0) msize(small)) ///
	(rcap max95 min95 label, lcolor(black)), ///
	xline(-1, lstyle(foreground)) ///
	yline(0, lcolor(red)) ///
	ytitle("`subtitle'") xsize(4.6) ///
	xlabel(-5(1)4) ///
	xtitle("Years Since School Transitioned to Traditional Calendar") ///
	legend(off)
	
graph export "figures/sun_`outcome'_`type'.pdf", replace

}
}




*---------------------------------------------------------
* Table 1: Summary Statistics (Creates Student and School Joint Table)
*---------------------------------------------------------
use "$data/main.dta"", clear

gen school_cal = 0 if ever_treated == 1 & concept6_school == 0 // 90-30 School
replace school_cal = . if ever_treated == 1 & concept6_school == 0 & middle == 1
replace school_cal = 1 if ever_treated == 1 & concept6_school == 1 // Concept 6 School
replace school_cal = 2 if ever_treated == 0 // Traditional School

label define school_cal 0 "90-30 Calendar" 1 "Concept 6 Calendar" ///
	2 "Always Traditional"

label values school_cal school_cal

local student_vars zcstela zcstmath absent_frac repeat_grade dropout ell

tabstat `student_vars', by(school_cal) stat(mean) save

foreach num of numlist 1/3{
	matrix define cal`num' = r(Stat`num')
}

matrix student_sum = cal1\cal2\cal3
	
matrix student_sum = student_sum'

foreach num of numlist 0/2{
	unique student_id if school_cal == `num'
	matrix define counttype`num' = r(N) \ r(unique)
}

matrix counttype = counttype0, counttype1, counttype2
matrix student_sum = student_sum \ counttype

mat colname student_sum = "90-30 Calendar" "Concept 6" ///
	 "Always Traditional"
	
mat rownames student_sum = "Standardized English Score" "Standardized Math Score" ///
	"Fraction of Days Absent" "Repeat a Grade" "Dropout" "English Language Learner" ///
	"Number of Student-Years" "Number of Students"

esttab matrix(student_sum, fmt("3 3 3 3 3 3 %15.3gc")) 

use "$data/main.dta"", clear
//603 schools traditional; 204 switchers	
	
drop if ever_treated == 1 & concept6_school == 0 & middle == 1
	collapse (mean) elem middle highschool member studteacher_ratio frac_*, by(school_id ever_treated concept6_school)
	drop frac_totfrl
	
	label var elem "Elementary Schools"
	label var middle "Middle Schools"
	label var highschool "Highschools"
	label var member " Avg Number of Students"
	label var studteacher_ratio "Student-teacher Ratio"
	label var frac_asian "Percent Students Asian"
	label var frac_hisp "Percent Students Hispanic"
	label var frac_black "Percent Students Black"
	label var frac_white "Percent Students White"
	label var frac_frelch "Percent Free Lunch Eligible"
	label var frac_redlch "Percent Reduced-price Lunch Eligible"
	
	* 90-30 Calendars
	statsmat member studteacher_ratio frac_* ///
		if ever_treated == 1 & concept6 == 0, stat(mean) matrix(sum_statsa) 	

	* Concept 6 Calendars
	statsmat member studteacher_ratio frac_* ///
		if ever_treated == 1 & concept6 == 1, stat(mean) matrix(sum_statsb)
	
	* Always Traditional Calendars
	statsmat member studteacher_ratio frac_* ///
		if ever_treated == 0, stat(mean) matrix(sum_statsc)
	
	
	count if ever_treated == 1 & concept6 == 0 & elem == 1
	matrix define count9030 = r(N)
	count if ever_treated == 1 & concept6 == 0 & middle == 1
	matrix count9030 = count9030 \ r(N)
	count if ever_treated == 1 & concept6 == 0 & highschool == 1
	matrix count9030 = count9030 \ r(N)

	
	count if ever_treated == 1 & concept6 == 1 & elem == 1
	matrix define countc6 = r(N)
	count if ever_treated == 1 & concept6 == 1 & middle == 1
	matrix countc6 = countc6 \ r(N)
	count if ever_treated == 1 & concept6 == 1 & highschool == 1
	matrix countc6 = countc6 \ r(N)
	

	count if ever_treated == 0 & elem == 1
	matrix define counttrad = r(N)
	count if ever_treated == 0 & middle == 1
	matrix  counttrad = counttrad \ r(N)
	count if ever_treated == 0 & highschool == 1
	matrix counttrad = counttrad \ r(N)


	matrix N_mat = count9030, countc6, counttrad
	
	matrix sum_stats = sum_statsa, sum_statsb, sum_statsc

	
	matrix sum_stats = N_mat\sum_stats
	
	matrix rowname sum_stats = "Elementary Schools" "Middle Schools" "High Schools" ///
	"Number of Students" "Student-Teacher Ratio" "Percent Students Asian" ///
	"Percent Students Hispanic" "Percent Students Black" "Percent Students White" ///
	"Percent Free Lunch Eligible" "Percent Reduced-Price Lunch"
	
	
	mat define blank1 = J(1,3,.)
	matrix rowname blank1 = "Students Ever Attend School Type"
	
	mat define blank2 = J(2,3,.)
	matrix rowname blank2 = "Schools Switch Calendar Type"
	
	mat school_student_stats = blank1 \ student_sum \ blank2 \ sum_stats
	
	 
frmttable using "tables/sum_stats.tex", replace tex statmat(school_student_stats) sdec(0\3\3\3\3\3\3\0\0\0\0\0\0\0\0\0\2\2\2\2\2\2) ///
	sfmt(fc) ctitle("","Transition from","Transition from", "Always" \ "","90-30 Calendar" , "Concept 6 Calendar", "Traditional")  ///
	rtitle("\textbf{A. Student-Level Measures}"\ ///
	"Standardized English Score" \ "Standardized Math Score" \ ///
	"Fraction of Days Absent" \"Repeat a Grade" \ "Dropout" \ ///
	"English Language Learner" \ "Number of Student-Years" \ "Number of Students" \ ""  \ ///
	"\textbf{B.School-Level Measures}"\ ///
	"Elementary Schools"\ "Middle Schools" \"High Schools" \ ///
	"Number of Students Enrolled" \"Student-Teacher Ratio" \"Fraction Asian"\ ///
	"Fraction Hispanic" \"Fraction Black" \"Fraction White"\ ///
	"Fraction Free Lunch Eligible"\ "Fraction Reduced-Price Lunch" ) ///
	fragment
	
filefilter "tables/sum_stats.tex" "tables/sum_stats1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/sum_stats1.tex" "tables/sum_stats.tex", from("\BSbegin{tabular}{lccc}") to("") replace
filefilter "tables/sum_stats.tex" "tables/sum_stats1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/sum_stats1.tex" "tables/sum_stats.tex", from("\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/sum_stats.tex" "tables/sum_stats1.tex", from("\BSend{center}") to("") replace
filefilter "tables/sum_stats1.tex" "tables/sum_stats.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/sum_stats.tex" "tables/sum_stats1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/sum_stats1.tex" "tables/sum_stats.tex", from("&  &  &") to("") replace

erase "tables/sum_stats1.tex"



*---------------------------------------------------------
* Table 2: Effect of 90-30 calendar (Elementary only)
*---------------------------------------------------------
*** 90-30 Calendars ***
use "$data/main.dta"", clear
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1


* Sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	gen sampleFE_`outcome' = e(sample)

}

mat means9030 = .
foreach var in zcstmath zcstela absent_frac repeat_grade dropout{
	sum `var' if sampleFE_`var' == 1
	mat means9030 = means9030 \ r(mean)
}




*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome', sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe.tex", replace tex statmat(twfe1) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars1) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{Elementary Schools}" \ "\cmidrule(lr){2-4}" , "(1)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment

	

*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe.tex", merge tex statmat(twfe2) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars2) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(2)")  rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment


*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe.tex", merge tex statmat(twfe3) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars3) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(3)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment


filefilter "tables/twfe.tex" "tables/twfe1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/twfe1.tex" "tables/twfe.tex", from("\BSbegin{tabular}{lccc}") to("") replace
filefilter "tables/twfe.tex" "tables/twfe1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/twfe1.tex" "tables/twfe.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/twfe.tex" "tables/twfe1.tex", from("\BSend{center}") to("") replace
filefilter "tables/twfe1.tex" "tables/twfe.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/twfe.tex" "tables/twfe1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/twfe1.tex" "tables/twfe.tex", from(" &  &  &  &  &  &") to("") replace

erase "tables/twfe1.tex"


*---------------------------------------------------------
* Table 3: Effect of C6 calendar By school level
*---------------------------------------------------------

*** Elementary Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if elem == 1

* Sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	gen sampleFE_`outcome' = e(sample)

}

*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe_byschooltype.tex", replace tex statmat(twfe1) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars1) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{Elementary Schools}" \ "\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}" , "(1)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment
	
*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype.tex", merge tex statmat(twfe2) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars2) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{Middle Schools}" \ "" , "(2)")  rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype.tex", merge tex statmat(twfe3) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars3) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{High Schools}" \ "" , "(3)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment
	


	
*** Middle Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if middle == 1


* Sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	gen sampleFE_`outcome' = e(sample)

}


*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars4 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe4 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe_byschooltype.tex", merge tex statmat(twfe4) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars4) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(4)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment


*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars5 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe5 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe_byschooltype.tex", merge tex statmat(twfe5) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars5) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(5)")  rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars6 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe6 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe_byschooltype.tex", merge tex statmat(twfe6) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars6) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(6)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment

		
*** High Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if highschool == 1

* Sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	gen sampleFE_`outcome' = e(sample)

}


*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars7 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe7 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe_byschooltype.tex", merge tex statmat(twfe7) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars7) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(7)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment
	

*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars8 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe8 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe_byschooltype.tex", merge tex statmat(twfe8) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars8) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(8)")  rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment


*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars9 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe9 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/twfe_byschooltype.tex", merge tex statmat(twfe9) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars9) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(9)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment
	

filefilter "tables/twfe_byschooltype.tex" "tables/twfe_byschooltype1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/twfe_byschooltype1.tex" "tables/twfe_byschooltype.tex", from("\BSbegin{tabular}{lccccccccc}") to("") replace
filefilter "tables/twfe_byschooltype.tex" "tables/twfe_byschooltype1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/twfe_byschooltype1.tex" "tables/twfe_byschooltype.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/twfe_byschooltype.tex" "tables/twfe_byschooltype1.tex", from("\BSend{center}") to("") replace
filefilter "tables/twfe_byschooltype1.tex" "tables/twfe_byschooltype.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/twfe_byschooltype.tex" "tables/twfe_byschooltype1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/twfe_byschooltype1.tex" "tables/twfe_byschooltype.tex", from(" &  &  &  &  &  & ") to("") replace

erase "tables/twfe_byschooltype1.tex"



*---------------------------------------------------------
* Table 4: Accounting for potential heterogeneous treatment effects (Borusyak with Lagged Test Scores)
*---------------------------------------------------------
* ssc install did_imputation


*** 90-30 Calendars ***
use "$data/main.dta"", clear
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade student_id) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}



*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

}


mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Concept 6 Calendars ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}

*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id) pretrends(4)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout



*** Elementary Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if elem == 1


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)
mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


	
*** Middle Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if middle == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars4 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe4 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout
		
*** High Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if highschool == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars5 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe5 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


matrix starsBlank = J(5,2,0)
mat stars = stars1, starsBlank, stars2, starsBlank, stars3, starsBlank, stars4, starsBlank, stars5, starsBlank
mat outcomes = twfe1, twfe2, twfe3, twfe4, twfe5




frmttable using "tables/BorusyakLagged.tex", replace tex statmat(outcomes) substat(3) sdec(0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{1}{c}{90-30 Calendar}", "\multicolumn{4}{c}{Concept 6 Calendar}" \ "\cmidrule(lr){2-2} \cmidrule(lr){3-6}" "Elementary Schools", "All Schools", "Elementary Schools", "Middle Schools", "High Schools" \ "" , "(1)", "(2)", "(3)", "(4)", "(5)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N") fragment


foreach table in BorusyakLagged{

filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSbegin{tabular}{lccccc}") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("&  &  &") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSend{center}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSbegin{footnotesize}") to("") replace


erase "tables/`table'1.tex"

}




*---------------------------------------------------------
* Table 5, 6, A.6: Split students into low, middle, high types (Concept 6)
*---------------------------------------------------------


foreach school_type in elem middle highschool{

*** Low-Score Students ***
use "$data/main.dta"", clear

capture drop group
gen group = g_overall

drop if concept6_school == 0 & ever_treated == 1
keep if `school_type' == 1



* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls3 if group == 0, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	tab samplelag_`outcome'
	
	gen sampleFE_`outcome' = e(sample)
}

*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1 & group == 0, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", replace tex statmat(twfe1) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars1) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{Low-Achieving}" \ "\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}" , "(2)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment
	
	

	
	
*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1 & group == 0, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", merge tex statmat(twfe2) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars2) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{Middle-Achieving}" \ "\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}" , "(2)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1 & group == 0, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}


mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", merge tex statmat(twfe3) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars3) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{High-Achieving}" \ "\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}" , "(3)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment


*** Middle-Score Students ***


* sample selection
foreach outcome of global outcomes{
	drop samplelag_`outcome' sampleFE_`outcome'
	qui reghdfe `outcome' trad $controls3 if group == 1, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	tab samplelag_`outcome'
	
	gen sampleFE_`outcome' = e(sample)
}


*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1 & group == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars4 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe4 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", merge tex statmat(twfe4) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars4) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(4)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment
	

*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1 & group == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars5 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe5 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", merge tex statmat(twfe5) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars5) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(5)")  ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1 & group == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}


mat stars6 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe6 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", merge tex statmat(twfe6) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars6) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(6)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment

	
*** High-Score Students ***

* sample selection
foreach outcome of global outcomes{
	drop samplelag_`outcome' sampleFE_`outcome'
	qui reghdfe `outcome' trad $controls3 if group == 2, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	tab samplelag_`outcome'
	
	gen sampleFE_`outcome' = e(sample)
}


*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1 & group == 2, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars7 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe7 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", merge tex statmat(twfe7) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars7) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(7)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment
	
*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1 & group == 2, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars8 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe8 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", merge tex statmat(twfe8) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars8) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(8)")  ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1 & group == 2, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}


mat stars9 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe9 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


matrix list stars

frmttable using "tables/lmh_c6`school_type'.tex", merge tex statmat(twfe9) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars9) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(9)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment


	

filefilter "tables/lmh_c6`school_type'.tex" "tables/lmh_c6`school_type'1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/lmh_c6`school_type'1.tex" "tables/lmh_c6`school_type'.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/lmh_c6`school_type'.tex" "tables/lmh_c6`school_type'1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/lmh_c6`school_type'1.tex" "tables/lmh_c6`school_type'.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/lmh_c6`school_type'.tex" "tables/lmh_c6`school_type'1.tex", from("\BSend{center}") to("") replace
filefilter "tables/lmh_c6`school_type'1.tex" "tables/lmh_c6`school_type'.tex", from("\BSbegin{tabular}{lccccccccc}") to("") replace
filefilter "tables/lmh_c6`school_type'.tex" "tables/lmh_c6`school_type'1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/lmh_c6`school_type'1.tex" "tables/lmh_c6`school_type'.tex", from("&  &  &  &  &  & ") to("") replace

erase "tables/lmh_c6`school_type'1.tex"

}




*---------------------------------------------------------
* Table 7: Teacher Turnover by experience
*---------------------------------------------------------
*** 90-30 Calendars ***
use "$main/teacher.dta", clear
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}



	
*** Diff-in-Diff ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher1 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher.tex", replace tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","\multicolumn{3}{c}{Transition from 90-30 Calendars}" \ "\cmidrule(lr){2-4} \cmidrule(lr){5-7}" , "(1)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "" \"Time-Varying School Controls", "") ///
	fragment

*** Add Lagged Test Scores ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher2 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","\multicolumn{3}{c}{Transition from Concept 6 Calendars}" \ "" , "(2)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \ "Time-Varying School Controls", "") ///
	fragment
	
*** Add School Controls ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher3 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(3)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \ "Time-Varying School Controls", "X") ///
	fragment
	

*** Concept 6 Calendars ***
use "$main/teacher.dta", clear
drop if concept6_school == 0 & ever_treated == 1


* FE sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}

*** Diff-in-Diff ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher1 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(4)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "" \ "Time-Varying School Controls", "") ///
	fragment

*** Add Lagged Test Scores ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher2 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(5)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \ "Time-Varying School Controls", "") ///
	fragment
	
*** Add School Controls ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacherTeacher3 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(6)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \ "Time-Varying School Controls", "X") ///
	fragment


filefilter "tables/teacher.tex" "tables/teacher1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/teacher1.tex" "tables/teacher.tex", from("\BSbegin{tabular}{lcccccc}") to("") replace
filefilter "tables/teacher.tex" "tables/teacher1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/teacher1.tex" "tables/teacher.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/teacher.tex" "tables/teacher1.tex", from("\BSend{center}") to("") replace
filefilter "tables/teacher1.tex" "tables/teacher.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/teacher.tex" "tables/teacher1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/teacher1.tex" "tables/teacher.tex", from(" &  &  &  &  &  & ") to("") replace

erase "tables/teacher1.tex"




*---------------------------------------------------------
* * Table 8: Teacher Turnover by experience and school-level type (Concept 6 Calendars ONLY)
*---------------------------------------------------------

*** ELEMENTARY SCHOOLS ***
use "$main/teacher.dta", clear

drop if concept6_school == 0 & ever_treated == 1
keep if elem == 1


* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}

*** Diff-in-Diff ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher1 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", replace tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ///
	ctitle("","\multicolumn{3}{c}{Elementary School}" \ "\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}" , "(1)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "" \ "Time-Varying School Controls", "") ///
	fragment

*** Add Lagged Test Scores ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher2 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","\multicolumn{3}{c}{Middle School}" \ "" , "(2)") ///
	rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \  "Time-Varying School Controls", "") ///
	fragment
	
*** Add School Controls ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher3 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","\multicolumn{3}{c}{High School}" \ "" , "(3)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \ "Time-Varying School Controls", "X") ///
	fragment
	

*** MIDDLE SCHOOLS ***
use "$main/teacher.dta", clear
drop if concept6_school == 0 & ever_treated == 1
keep if middle == 1


* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}

*** Diff-in-Diff ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher1 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(4)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "" \  "Time-Varying School Controls", "") ///
	fragment

*** Add Lagged Test Scores ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher2 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(5)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \ "Time-Varying School Controls", "") ///
	fragment
	
	
*** Add School Controls ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher3 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(6)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \  "Time-Varying School Controls", "X") ///
	fragment
	

*** HIGH SCHOOLS ***
use "$main/teacher.dta", clear
drop if concept6_school == 0 & ever_treated == 1
keep if highschool == 1


* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}

*** Diff-in-Diff ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher1 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(7)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "" \ "Time-Varying School Controls", "") ///
	fragment

*** Add Lagged Test Scores ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher2 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(8)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \ "Time-Varying School Controls", "") ///
	fragment
	
*** Add School Controls ***
foreach outcome of global outcomes_teacher{

reghdfe `outcome' trad $controlsTeacher3 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix list stars

frmttable using "tables/teacher_schooltype.tex", merge tex statmat(twfe) substat(4) sdec(3) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(gc) ctitle("","" \ "" , "(9)") rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Average Grade Test Scores", "X" \  "Time-Varying School Controls", "X") ///
	fragment
	

filefilter "tables/teacher_schooltype.tex" "tables/teacher_schooltype1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/teacher_schooltype1.tex" "tables/teacher_schooltype.tex", from("\BSbegin{tabular}{lccccccccc}") to("") replace
filefilter "tables/teacher_schooltype.tex" "tables/teacher_schooltype1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/teacher_schooltype1.tex" "tables/teacher_schooltype.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/teacher_schooltype.tex" "tables/teacher_schooltype1.tex", from("\BSend{center}") to("") replace
filefilter "tables/teacher_schooltype1.tex" "tables/teacher_schooltype.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/teacher_schooltype.tex" "tables/teacher_schooltype1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/teacher_schooltype1.tex" "tables/teacher_schooltype.tex", from("&  &  &  &  &  & ") to("") replace

erase "tables/teacher_schooltype1.tex"





********************************************************************************

** APPENDIX FIGURES AND TABLES

********************************************************************************

*---------------------------------------------------------
* Figure A.1: National Distribution of School Hours
*---------------------------------------------------------
* From https://nces.ed.gov/programs/statereform/tab5_14.asp

import excel "$data/schoolHours.xlsx", sheet("Sheet1") firstrow clear
drop stname ZillowCode stusps

reshape long time_, i(st) j(grade)
rename time_ time
rename st fipst
replace time = time - 180 if fipst == 48

tempfile temp
save `temp', replace

import delimited "$data/ccdStudentsInEachState.csv", clear

keep if total_indicator == "Subtotal 4 - By Grade"

replace grade = subinstr(grade, "Grade ", "",.)
gen gradeNew = .
foreach num of numlist 1/12{
	replace gradeNew = `num' if grade == "`num'"
}

collapse (sum) student_count, by(fipst gradeNew statename)

drop if gradeNew == .
rename gradeNew grade

merge 1:1 fipst grade using `temp'
drop if _merge == 1
drop _merge


histogram time [fw = student_count], title(All Grades) xlabel(700(50)1200) ylabel(0(.01).06) xsize(4.6) xtitle("Minumum Required Yearly Hours") name(all, replace)

graph export "figures/minHoursAll.pdf", replace

histogram time [fw = student_count] if grade <= 5, title(Elementary School) xlabel(700(50)1200)  ylabel(0(.01).06) xsize(4.6) xtitle("Minumum Required Yearly Hours") name(elem, replace)
graph export "figures/minHoursElem.pdf", replace

histogram time [fw = student_count] if grade > 5 & grade <= 8, title(Middle School) xlabel(700(50)1200) ylabel(0(.01).06) xsize(4.6) xtitle("Minumum Required Yearly Hours") name(middle, replace)
graph export "figures/minHoursMiddle.pdf", replace

histogram time [fw = student_count] if grade >= 9, title(High School) xlabel(700(50)1200) ylabel(0(.01).06) xsize(4.6) xtitle("Minumum Required Yearly Hours") name(highschool, replace)
graph export "figures/minHoursHigh.pdf", replace

*---------------------------------------------------------
* Figure A.2: LAUSD student enrollment over time
*---------------------------------------------------------
* from https://www.cde.ca.gov/ds/ad/filesenr.asp
import delimited "$data/student_population.csv", clear encoding(UTF-8)
rename losangelesunified population
split year, parse(-)
keep year1 population
rename year1 year
destring year, replace
drop if year == 2019


colorpalette lin brands, select(2 4 5 6) nograph
	
twoway connected population year,  ///
	ylabel(575000(25000)775000, format(%12.0fc)) xsize(8) ///
	xlabel(1988(3)2018, format(%12.0f)) ///
	xtitle("Year") ///
	ytitle("Number of Students") ///
	lcolor("`r(p3)'") msymbol(0) mcolor("`r(p4)'")
	
graph export "figures/stdpop_lausd.pdf", replace


*---------------------------------------------------------
* Figures A.3 - A.6: Create study-event graphs without correcting for heterogeneous treatment effects, by school level
*---------------------------------------------------------
use "$data/main.dta"", clear

* concept6 schools

drop if concept6_school == 0 & ever_treated == 1 // Keep only concept 6 schools and those without cal changes


*** Elementary Schools ***
eventdd zcstmath $controls4 if elem == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Standardized Math Scores") ///
	legend(off) ///
	ylabel(-.5(.2).3) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)

graph export "figures/elem_math.pdf", replace

eventdd zcstela $controls4 if elem == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Standardized English Scores") ///
	legend(off) ///
	ylabel(-.3(.2).3) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)
	
graph export "figures/elem_eng.pdf", replace

eventdd absent_frac $controls4 if elem == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Fraction of Days Absent") ///
	legend(off) ///
	ylabel(-.01(.005).01) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)
	
graph export "figures/elem_absent.pdf", replace

eventdd repeat_grade $controls4 if elem == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Repeat Grade") ///
	legend(off) ///
	ylabel(-.04(.02).04) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)
	
graph export "figures/elem_repeatgrade.pdf", replace

eventdd dropout $controls3 if elem == 1, hdfe absorb(grade_by_year school_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Dropout") ///
	legend(off) ///
	ylabel(-.14(.02).06) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)
	
graph export "figures/elem_dropout.pdf", replace


*** Middle Schools ***
eventdd zcstmath $controls4 if middle == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Standardized Math Scores") ///
	legend(off) ///
	ylabel(-.5(.5).15) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)

graph export "figures/middle_math.pdf", replace

eventdd zcstela $controls4 if middle == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Standardized English Scores") ///
	legend(off) ///
	ylabel(-.3(.2).3) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)
	
graph export "figures/middle_eng.pdf", replace

eventdd absent_frac $controls4 if middle == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Fraction of Days Absent") ///
	legend(off) ///
	ylabel(-.03(.02).03) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)
	
graph export "figures/middle_absent.pdf", replace

eventdd repeat_grade $controls4 if middle == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Repeat Grade") ///
	legend(off) ///
	ylabel(-.005(.002).009) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)
	
graph export "figures/middle_repeatgrade.pdf", replace

eventdd dropout $controls3 if middle == 1, hdfe absorb(grade_by_year school_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Dropout") ///
	legend(off) ///
	ylabel(-.05(.02).05) xsize(4.6) ///
	xlabel(-5(1)5) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(5) inrange baseline($base)
	
graph export "figures/middle_dropout.pdf", replace

*** High Schools ***
eventdd zcstmath $controls4 if highschool == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Standardized Math Scores") ///
	legend(off) ///
	ylabel(-.4(.2).6) xsize(4.6) ///
	xlabel(-5(1)4) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(4) inrange baseline($base)

graph export "figures/highschool_math.pdf", replace

eventdd zcstela $controls4 if highschool == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Standardized English Scores") ///
	legend(off) ///
	ylabel(-.2(.1).3) xsize(4.6) ///
	xlabel(-5(1)4) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(4) inrange baseline($base)
	
graph export "figures/highschool_eng.pdf", replace

eventdd absent_frac $controls4 if highschool == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Fraction of Days Absent") ///
	legend(off) ///
	ylabel(-.05(.02).02) xsize(4.6) ///
	xlabel(-5(1)4) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(4) inrange baseline($base)
	
graph export "figures/highschool_absent.pdf", replace

eventdd repeat_grade $controls4 if highschool == 1, hdfe absorb(grade_by_year school_id student_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Repeat Grade") ///
	legend(off) ///
	ylabel(-.1(.05).25) xsize(4.6) ///
	xlabel(-5(1)4) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(4) inrange baseline($base)
	
graph export "figures/highschool_repeatgrade.pdf", replace

eventdd dropout $controls3 if highschool == 1, hdfe absorb(grade_by_year school_id) ///
	timevar(time) ci(rcap, lcolor(black)) cluster(school_id) ///
	graph_op(ytitle("Dropout") ///
	legend(off) ///
	ylabel(-.04(.02).1) xsize(4.6) ///
	xlabel(-5(1)4) xtitle("Years Since School Transitioned to Traditional Calendar")) ///
	leads(5) lags(4) inrange baseline($base)
	
graph export "figures/highschool_dropout.pdf", replace



*---------------------------------------------------------
* * Figure A.7-A.10: Pre-Trend Adjusted Dynamic Effects (Applying Freyaldenhoven, S. et al. (2021) -- Cumulative effects accounting for pre-trends)
*---------------------------------------------------------

*** 90-30 schools ***
foreach outcome of global outcomes {
use "$data/main.dta"", clear

gen treated = 0 
replace treated = 1 if year >= yearChange & yearChange != .

xtset, clear	

drop if concept6_school == 1 & ever_treated == 1 // Keep only 90-30 schools and those without cal changes
keep if elem == 1
	
	
label var zcstela "Standardized English Test Scores"
label var zcstmath "Standardized Math Test Scores"
label var absent_frac "Fraction of Days Absent"
label var repeat_grade "Probability of Repeating Grade"
label var dropout "Probability of Droppping Out"

local subtitle: variable label `outcome'

if "`outcome'" != "dropout"{
	display "Student"
	
	xtevent `outcome' $controls3, policyvar(treated) ///
window(4) repeatedcs panelvar(school_id) timevar(year) reghdfe addabsorb(i.school_id i.grade_by_year) vce(cluster school_id) note trend(-3) 

colorpalette lin brands, select(2 4 5 6) nograph
xteventplot, nosupt nominus1label scatterplotopts(mcolor("`r(p1)'") msymbol(0) msize(small))ciplotopts(lcolor(black)) ytitle("`subtitle'") xsize(4.6)

}

if "`outcome'" == "dropout"{
	display "Lagged"
	
	xtevent `outcome' $controls3, policyvar(treated) ///
window(4) repeatedcs panelvar(school_id) timevar(year) reghdfe addabsorb(i.school_id i.grade_by_year) vce(cluster school_id) note trend(-3) 

colorpalette lin brands, select(2 4 5 6) nograph
xteventplot, nosupt nominus1label scatterplotopts(mcolor("`r(p1)'") msymbol(0) msize(small))ciplotopts(lcolor(black)) ytitle("`subtitle'") xsize(4.6)
}

	
	
graph export "figures/FreyT_`outcome'_9030.pdf", replace


}


*** Concept 6 schools ***
foreach type in elem{
foreach outcome of global outcomes{
use "$data/main.dta"", clear

drop if concept6_school == 0 & ever_treated == 1 // Keep only concept 6 schools and those without cal changes
keep if `type' == 1

gen treated = 0 
replace treated = 1 if year >= yearChange & yearChange != .


label var zcstela "Standardized English Test Scores"
label var zcstmath "Standardized Math Test Scores"
label var absent_frac "Fraction of Days Absent"
label var repeat_grade "Probability of Repeating Grade"
label var dropout "Probability of Droppping Out"

local subtitle: variable label `outcome'


// In our case, control = 1 and treatment moves from 1 to 0. (i.e. backwards than expected) // tradition event study has control as 0 and treatment as 1

gen trad2 = 1-trad // Redefine treatment (Moving from treated to untreated)


xtset, clear	


if "`outcome'" != "dropout"{
	display "Student"
	
	xtevent `outcome' $controls3, policyvar(treated) ///
window(4) repeatedcs panelvar(school_id) timevar(year) reghdfe addabsorb(i.school_id i.grade_by_year) vce(cluster school_id) note trend(-3) 

colorpalette lin brands, select(2 4 5 6) nograph
xteventplot, nosupt nominus1label scatterplotopts(mcolor("`r(p1)'") msymbol(0) msize(small))ciplotopts(lcolor(black)) ytitle("`subtitle'") xsize(4.6)

}

if "`outcome'" == "dropout"{
	display "Lagged"
	
	xtevent `outcome' $controls3, policyvar(treated) ///
window(4) repeatedcs panelvar(school_id) timevar(year) reghdfe addabsorb(i.school_id i.grade_by_year) vce(cluster school_id) note trend(-3) 

colorpalette lin brands, select(2 4 5 6) nograph
xteventplot, nosupt nominus1label scatterplotopts(mcolor("`r(p1)'") msymbol(0) msize(small))ciplotopts(lcolor(black)) ytitle("`subtitle'") xsize(4.6)
}


	
graph export "figures/FreyT_`outcome'_`type'.pdf", replace

}
}


foreach type in middle{
foreach outcome of global outcomes{
use "$data/main.dta"", clear

drop if concept6_school == 0 & ever_treated == 1 // Keep only concept 6 schools and those without cal changes
keep if `type' == 1

gen treated = 0 
replace treated = 1 if year >= yearChange & yearChange != .


label var zcstela "Standardized English Test Scores"
label var zcstmath "Standardized Math Test Scores"
label var absent_frac "Fraction of Days Absent"
label var repeat_grade "Probability of Repeating Grade"
label var dropout "Probability of Droppping Out"

local subtitle: variable label `outcome'


// In our case, control = 1 and treatment moves from 1 to 0. (i.e. backwards than expected) // tradition event study has control as 0 and treatment as 1

gen trad2 = 1-trad // Redefine treatment (Moving from treated to untreated)


xtset, clear	


if "`outcome'" != "dropout"{
	display "Student"
	
	xtevent `outcome' $controls3, policyvar(treated) ///
window(-3 4) repeatedcs panelvar(school_id) timevar(year) reghdfe addabsorb(i.school_id i.grade_by_year) vce(cluster school_id) note trend(-3) 

colorpalette lin brands, select(2 4 5 6) nograph
xteventplot, nosupt nominus1label scatterplotopts(mcolor("`r(p1)'") msymbol(0) msize(small))ciplotopts(lcolor(black)) ytitle("`subtitle'") xsize(4.6)

}

if "`outcome'" == "dropout"{
	display "Lagged"
	
	xtevent `outcome' $controls3, policyvar(treated) ///
window(-3 4) repeatedcs panelvar(school_id) timevar(year) reghdfe addabsorb(i.school_id i.grade_by_year) vce(cluster school_id) note trend(-3) 

colorpalette lin brands, select(2 4 5 6) nograph
xteventplot, nosupt nominus1label scatterplotopts(mcolor("`r(p1)'") msymbol(0) msize(small))ciplotopts(lcolor(black)) ytitle("`subtitle'") xsize(4.6)
}


	
graph export "figures/FreyT_`outcome'_`type'.pdf", replace

}
}


foreach type in highschool{
foreach outcome of global outcomes{
use "$data/main.dta"", clear

drop if concept6_school == 0 & ever_treated == 1 // Keep only concept 6 schools and those without cal changes
keep if `type' == 1

gen treated = 0 
replace treated = 1 if year >= yearChange & yearChange != .


label var zcstela "Standardized English Test Scores"
label var zcstmath "Standardized Math Test Scores"
label var absent_frac "Fraction of Days Absent"
label var repeat_grade "Probability of Repeating Grade"
label var dropout "Probability of Droppping Out"


local subtitle: variable label `outcome'

// In our case, control = 1 and treatment moves from 1 to 0. (i.e. backwards than expected) // tradition event study has control as 0 and treatment as 1

gen trad2 = 1-trad // Redefine treatment (Moving from treated to untreated)

xtset, clear	

if "`outcome'" != "dropout"{
	display "Student"
	
	xtevent `outcome' $controls3, policyvar(treated) ///
window(-4 3) repeatedcs panelvar(school_id) timevar(year) reghdfe addabsorb(i.school_id i.grade_by_year) vce(cluster school_id) note trend(-3) 

colorpalette lin brands, select(2 4 5 6) nograph
xteventplot, nosupt nominus1label scatterplotopts(mcolor("`r(p1)'") msymbol(0) msize(small))ciplotopts(lcolor(black)) ytitle("`subtitle'") xsize(4.6)

}

if "`outcome'" == "dropout"{
	display "Lagged"
	
	xtevent `outcome' $controls3, policyvar(treated) ///
window(-4 3) repeatedcs panelvar(school_id) timevar(year) reghdfe addabsorb(i.school_id i.grade_by_year) vce(cluster school_id) note trend(-3) 

colorpalette lin brands, select(2 4 5 6) nograph
xteventplot, nosupt nominus1label scatterplotopts(mcolor("`r(p1)'") msymbol(0) msize(small))ciplotopts(lcolor(black)) ytitle("`subtitle'") xsize(4.6)
}



graph export "figures/FreyT_`outcome'_`type'.pdf", replace

}
}



*---------------------------------------------------------
* Tables A.1-A.3: Summary Statistics, by School Grade
*---------------------------------------------------------

*** For elem and middle schools ***
foreach type in elem middle{

use "$data/main.dta"", clear

keep if `type' == 1

gen school_cal = 0 if ever_treated == 1 & concept6_school == 0 // 90-30 School
replace school_cal = 1 if ever_treated == 1 & concept6_school == 1 // Concept 6 School
replace school_cal = 2 if ever_treated == 0 // Traditional School

label define school_cal 0 "90-30 Calendar" 1 "Concept 6 Calendar" ///
	2 "Always Traditional"

label values school_cal school_cal

local student_vars zcstela zcstmath absent_frac repeat_grade dropout ell

tabstat `student_vars', by(school_cal) stat(mean) save

foreach num of numlist 1/3{
	matrix define cal`num' = r(Stat`num')
}

matrix student_sum = cal1\cal2\cal3
	
matrix student_sum = student_sum'

foreach num of numlist 0/2{
	unique student_id if school_cal == `num'
	matrix define counttype`num' = r(N) \ r(unique)
}

matrix counttype = counttype0, counttype1, counttype2
matrix student_sum = student_sum \ counttype

mat colname student_sum = "90-30 Calendar" "Concept 6" ///
	 "Always Traditional"
	
mat rownames student_sum = "Standardized English Score" "Standardized Math Score" ///
	"Fraction of Days Absent" "Repeat a Grade" "Dropout" "English Language Learner" ///
	"Number of Student-Years" "Number of Students"

esttab matrix(student_sum, fmt("3 3 3 3 3 3 %15.3gc")) 

use "$data/main.dta"", clear

keep if `type' == 1
//603 schools traditional; 204 switchers	
	
	collapse (mean) member studteacher_ratio frac_*, by(school_id ever_treated concept6_school)
	drop frac_totfrl
	
	label var member " Avg Number of Students"
	label var studteacher_ratio "Student-teacher Ratio"
	label var frac_asian "Percent Students Asian"
	label var frac_hisp "Percent Students Hispanic"
	label var frac_black "Percent Students Black"
	label var frac_white "Percent Students White"
	label var frac_frelch "Percent Free Lunch Eligible"
	label var frac_redlch "Percent Reduced-price Lunch Eligible"
	
	* 90-30 Calendars
	statsmat member studteacher_ratio frac_* ///
		if ever_treated == 1 & concept6 == 0, stat(mean) matrix(sum_statsa) 	

	* Concept 6 Calendars
	statsmat member studteacher_ratio frac_* ///
		if ever_treated == 1 & concept6 == 1, stat(mean) matrix(sum_statsb)
	
	* Always Traditional Calendars
	statsmat member studteacher_ratio frac_* ///
		if ever_treated == 0, stat(mean) matrix(sum_statsc)
	
	
	count if ever_treated == 1 & concept6 == 0
	matrix define count9030 = r(N)

	
	count if ever_treated == 1 & concept6 == 1
	matrix define countc6 = r(N)

	
	count if ever_treated == 0
	matrix define counttrad = r(N)


	matrix N_mat = count9030, countc6, counttrad
	
	matrix sum_stats = sum_statsa, sum_statsb, sum_statsc

	
	matrix sum_stats = N_mat\sum_stats
	
	matrix rowname sum_stats = "Number of Students" "Student-Teacher Ratio" "Percent Students Asian" ///
	"Percent Students Hispanic" "Percent Students Black" "Percent Students White" ///
	"Percent Free Lunch Eligible" "Percent Reduced-Price Lunch"
	
	
	mat define blank1 = J(1,3,.)
	matrix rowname blank1 = "Students Ever Attend School Type"
	
	mat define blank2 = J(2,3,.)
	matrix rowname blank2 = "Schools Switch Calendar Type"
	
	mat school_student_stats = blank1 \ student_sum \ blank2 \ sum_stats
	
	 
frmttable using "tables/sum_stats`type'.tex", replace tex statmat(school_student_stats) sdec(0\3\3\3\3\3\3\0\0\0\0\0\0\0\2\2\2\2\2\2) ///
	sfmt(fc) ctitle("","Transition from","Transition from", "Always" \ "","90-30 Calendar" , "Concept 6 Calendar", "Traditional")  ///
	rtitle("\textbf{A. Student-Level Measures}"\ ///
	"Standardized English Score" \ "Standardized Math Score" \ ///
	"Fraction of Days Absent" \"Repeat a Grade" \ "Dropout" \ ///
	"English Language Learner" \ "Number of Student-Years" \ "Number of Students" \ ""  \ ///
	"\textbf{B.School-Level Measures}"\ "Number of Schools" \ ///
	"Number of Students Enrolled" \"Student-Teacher Ratio" \"Fraction Asian"\ ///
	"Fraction Hispanic" \"Fraction Black" \"Fraction White"\ ///
	"Fraction Free Lunch Eligible"\ "Fraction Reduced-Price Lunch" ) ///
	fragment
	
filefilter "tables/sum_stats`type'.tex" "tables/sum_stats`type'1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/sum_stats`type'1.tex" "tables/sum_stats`type'.tex", from("\BSbegin{tabular}{lccc}") to("") replace
filefilter "tables/sum_stats`type'.tex" "tables/sum_stats`type'1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/sum_stats`type'1.tex" "tables/sum_stats`type'.tex", from("\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/sum_stats`type'.tex" "tables/sum_stats`type'1.tex", from("\BSend{center}") to("") replace
filefilter "tables/sum_stats`type'1.tex" "tables/sum_stats`type'.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/sum_stats`type'.tex" "tables/sum_stats`type'1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/sum_stats`type'1.tex" "tables/sum_stats`type'.tex", from("&  &  &") to("") replace

erase "tables/sum_stats`type'1.tex"

}


*** For High schools ***
use "$data/main.dta"", clear

keep if highschool == 1

gen school_cal = 0 if ever_treated == 1 & concept6_school == 0 // 90-30 School
replace school_cal = 1 if ever_treated == 1 & concept6_school == 1 // Concept 6 School
replace school_cal = 2 if ever_treated == 0 // Traditional School

label define school_cal 0 "90-30 Calendar" 1 "Concept 6 Calendar" ///
	2 "Always Traditional"

label values school_cal school_cal

local student_vars zcstela zcstmath absent_frac repeat_grade dropout ell

tabstat `student_vars', by(school_cal) stat(mean) save

foreach num of numlist 1/3{
	matrix define cal`num' = r(Stat`num')
}

matrix student_sum = cal1\cal2
	
matrix student_sum = student_sum'

foreach num of numlist 0/2{
	unique student_id if school_cal == `num'
	matrix define counttype`num' = r(N) \ r(unique)
}

matrix counttype = counttype1, counttype2
matrix student_sum = student_sum \ counttype

mat colname student_sum = "Concept 6" ///
	 "Always Traditional"
	
mat rownames student_sum = "Standardized English Score" "Standardized Math Score" ///
	"Fraction of Days Absent" "Repeat a Grade" "Dropout" "English Language Learner" ///
	"Number of Student-Years" "Number of Students"

esttab matrix(student_sum, fmt("3 3 3 3 3 3 %15.3gc")) 

use "$data/main.dta"", clear

keep if highschool == 1
//603 schools traditional; 204 switchers	
	
	collapse (mean) member studteacher_ratio frac_*, by(school_id ever_treated concept6_school)
	drop frac_totfrl
	
	label var member " Avg Number of Students"
	label var studteacher_ratio "Student-teacher Ratio"
	label var frac_asian "Percent Students Asian"
	label var frac_hisp "Percent Students Hispanic"
	label var frac_black "Percent Students Black"
	label var frac_white "Percent Students White"
	label var frac_frelch "Percent Free Lunch Eligible"
	label var frac_redlch "Percent Reduced-price Lunch Eligible"
	
	* Concept 6 Calendars
	statsmat member studteacher_ratio frac_* ///
		if ever_treated == 1 & concept6 == 1, stat(mean) matrix(sum_statsb)
	
	* Always Traditional Calendars
	statsmat member studteacher_ratio frac_* ///
		if ever_treated == 0, stat(mean) matrix(sum_statsc)
	
	count if ever_treated == 1 & concept6 == 1
	matrix define countc6 = r(N)

	
	count if ever_treated == 0
	matrix define counttrad = r(N)


	matrix N_mat = countc6, counttrad
	
	matrix sum_stats = sum_statsb, sum_statsc

	
	matrix sum_stats = N_mat\sum_stats
	
	matrix rowname sum_stats = "Number of Students" "Student-Teacher Ratio" "Percent Students Asian" ///
	"Percent Students Hispanic" "Percent Students Black" "Percent Students White" ///
	"Percent Free Lunch Eligible" "Percent Reduced-Price Lunch"
	
	
	mat define blank1 = J(1,2,.)
	matrix rowname blank1 = "Students Ever Attend School Type"
	
	mat define blank2 = J(2,2,.)
	matrix rowname blank2 = "Schools Switch Calendar Type"
	
	mat school_student_stats = blank1 \ student_sum \ blank2 \ sum_stats
	
	 
frmttable using "tables/sum_statshighschool.tex", replace tex statmat(school_student_stats) sdec(0\3\3\3\3\3\3\0\0\0\0\0\0\0\2\2\2\2\2\2) ///
	sfmt(fc) ctitle("","Transition from", "Always" \ "", "Concept 6 Calendar", "Traditional")  ///
	rtitle("\textbf{A. Student-Level Measures}"\ ///
	"Standardized English Score" \ "Standardized Math Score" \ ///
	"Fraction of Days Absent" \"Repeat a Grade" \ "Dropout" \ ///
	"English Language Learner" \ "Number of Student-Years" \ "Number of Students" \ ""  \ ///
	"\textbf{B.School-Level Measures}"\ "Number of Schools" \ ///
	"Number of Students Enrolled" \"Student-Teacher Ratio" \"Fraction Asian"\ ///
	"Fraction Hispanic" \"Fraction Black" \"Fraction White"\ ///
	"Fraction Free Lunch Eligible"\ "Fraction Reduced-Price Lunch" ) ///
	fragment
	
filefilter "tables/sum_statshighschool.tex" "tables/sum_statshighschool1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/sum_statshighschool1.tex" "tables/sum_statshighschool.tex", from("\BSbegin{tabular}{lcc}") to("") replace
filefilter "tables/sum_statshighschool.tex" "tables/sum_statshighschool1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/sum_statshighschool1.tex" "tables/sum_statshighschool.tex", from("\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/sum_statshighschool.tex" "tables/sum_statshighschool1.tex", from("\BSend{center}") to("") replace
filefilter "tables/sum_statshighschool1.tex" "tables/sum_statshighschool.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/sum_statshighschool.tex" "tables/sum_statshighschool1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/sum_statshighschool1.tex" "tables/sum_statshighschool.tex", from("&  &  &") to("") replace

erase "tables/sum_statshighschool1.tex"




*---------------------------------------------------------
* Table A.4: Testing for Parallel Trends (Borusyak Test)
*---------------------------------------------------------
*** 90-30 Calendars ***
use "$data/main.dta"", clear
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade student_id) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}



*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.001) maxit(10000) cluster(school_id) pretrends(5)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat preF`outcome'90 =  e(pre_F)
mat preP`outcome'90 = e(pre_p)
mat prepdf`outcome'90 = e(pre_df)

mat list preF`outcome'90
mat list preP`outcome'90
mat list prepdf`outcome'90

}


mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Elementary Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if elem == 1


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.001) maxit(10000) cluster(school_id) pretrends(5)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'
mat preF`outcome'c6elem =  e(pre_F)
mat preP`outcome'c6elem = e(pre_p)
mat prepdf`outcome'c6elem = e(pre_df)

mat list preP`outcome'c6elem

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


	
*** Middle Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if middle == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.001) maxit(10000) cluster(school_id) pretrends(5)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

mat preF`outcome'c6middle =  e(pre_F)
mat preP`outcome'c6middle = e(pre_p)
mat prepdf`outcome'c6middle = e(pre_df)

mat list preP`outcome'c6middle

}

mat stars4 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe4 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout
		
*** High Schools ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1
keep if highschool == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.001) maxit(10000) cluster(school_id) pretrends(5)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'
mat preF`outcome'c6high =  e(pre_F)
mat preP`outcome'c6high = e(pre_p)
mat prepdf`outcome'c6high = e(pre_df)

mat list preP`outcome'c6high

}

foreach outcome of global outcomes{
	mat list preP`outcome'90	
	mat list preP`outcome'c6elem
	mat list preP`outcome'c6middle
	mat list preP`outcome'c6high
}

mat title = J(1,1,.)


foreach type in 90 c6elem c6middle c6high{
	mat pt`type' = title, preFzcstmath`type', prePzcstmath`type' \ title, preFzcstela`type', prePzcstela`type' \ title, preFabsent_frac`type', prePabsent_frac`type' \ title, preFrepeat_grade`type', prePrepeat_grade`type' \ title, preFdropout`type', prePdropout`type'
}



mat parallelTrends = pt90, ptc6elem, ptc6middle, ptc6high


frmttable using "tables/BorusyakParallelTrends.tex", replace tex statmat(parallelTrends) substat(2) sdec(3) ///
	brackets("","" \ "",""  \ "","" \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{1}{c}{90-30 Calendar}", "\multicolumn{3}{c}{Concept 6 Calendar}" \ "\cmidrule(lr){2-2} \cmidrule(lr){3-5}" "Elementary Schools", "Elementary Schools", "Middle Schools", "High Schools" \ "" , "(1)", "(2)", "(3)", "(4)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"F Statistic"\"P-value"\"\textbf{B. Standardized English Scores}"\"F Statistic"\"P-value"\"\textbf{C. Fraction of Days Absent}"\"F Statistic"\"P-value"\"\textbf{D. Grade is Repeated}"\"F Statistic"\"P-value"\"\textbf{E. Drops Out of High School}"\"F Statistic"\"P-value") fragment


foreach table in BorusyakParallelTrends{

filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSbegin{tabular}{lcccc}") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("&  &  &") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSend{center}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSbegin{footnotesize}") to("") replace


erase "tables/`table'1.tex"

}



*---------------------------------------------------------
* Table A.5: Split students into low, middle, high types (90-30 calendar)
*---------------------------------------------------------
*** 90-30 Calendar ***
use "$data/main.dta"", clear

gen group = g_overall

	
*** Low-Score Students ***
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls3 if group == 0, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	tab samplelag_`outcome'
	
	gen sampleFE_`outcome' = e(sample)
}

*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1 & group == 0, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout
	
*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1 & group == 0, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1 & group == 0, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Middle-Score Students ***

* sample selection
foreach outcome of global outcomes{
	drop samplelag_`outcome' sampleFE_`outcome'
	qui reghdfe `outcome' trad $controls3 if group == 1, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	tab samplelag_`outcome'
	
	gen sampleFE_`outcome' = e(sample)
}

*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1 & group == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars4 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe4 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1 & group == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars5 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe5 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1 & group == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars6 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe6 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

*** High-Score Students ***

* sample selection
foreach outcome of global outcomes{
	drop samplelag_`outcome' sampleFE_`outcome'
	qui reghdfe `outcome' trad $controls3 if group == 2, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	tab samplelag_`outcome'
	
	gen sampleFE_`outcome' = e(sample)
}

*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1 & group == 2, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars7 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe7 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1 & group == 2, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars8 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe8 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1 & group == 2, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars9 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe9 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

frmttable using "tables/lmh_9030.tex", merge tex statmat(twfe9) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars9) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(9)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment


	

filefilter "tables/lmh_9030.tex" "tables/lmh_90301.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/lmh_90301.tex" "tables/lmh_9030.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/lmh_9030.tex" "tables/lmh_90301.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/lmh_90301.tex" "tables/lmh_9030.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/lmh_9030.tex" "tables/lmh_90301.tex", from("\BSend{center}") to("") replace
filefilter "tables/lmh_90301.tex" "tables/lmh_9030.tex", from("\BSbegin{tabular}{lccccccccc}") to("") replace
filefilter "tables/lmh_9030.tex" "tables/lmh_90301.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/lmh_90301.tex" "tables/lmh_9030.tex", from("&  &  &  &  &  & ") to("") replace

erase "tables/lmh_90301.tex"


*---------------------------------------------------------
* Tables A.7, A.8, A.9, A.10: Accounting for potential heterogeneous treatment effects, by achievement levels with Lagged Test Scores (Borusyak with Lagged Test Scores)
*---------------------------------------------------------
// ssc install did_imputation


*** 90-30 Calendars ***


*** Low-Score Students  group == 0 ***
use "$data/main.dta"", clear
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

gen group = g_overall
keep if group == 0

* sample selection
foreach outcome of global outcomes{
	reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}



*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

}


mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Middle-Score Students  group == 1 ***
use "$data/main.dta"", clear
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

gen group = g_overall
keep if group == 1


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}

*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id) pretrends(4)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout



*** High-Score Students group == 2 ***
use "$data/main.dta"", clear
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

gen group = g_overall
keep if group == 2


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)
mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


mat zeros = [0\ 0\ 0\ 0\ 0]

foreach value of numlist 1/3{
	mat stars`value'_temp = stars`value', zeros, zeros
}


mat outcomes = twfe1, twfe2, twfe3
mat stars = stars1_temp, stars2_temp, stars3_temp


frmttable using "tables/BorusyakLagged_9030schools.tex", replace tex statmat(outcomes) substat(3) sdec(0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","Low-Achieving", "Middle-Achieving", "High-Achieving" \ "" , "(1)", "(2)", "(3)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N") fragment
	
	
	

*** C6 Elementary ***

*** Low-Score Students  group == 0 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if elem == 1

gen group = g_overall
keep if group == 0

* sample selection
foreach outcome of global outcomes{
	reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}



*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

}


mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Middle-Score Students  group == 1 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if elem == 1

gen group = g_overall
keep if group == 1


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}

*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id) pretrends(4)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout



*** High-Score Students group == 2 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if elem == 1

gen group = g_overall
keep if group == 2


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)
mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


mat zeros = [0\ 0\ 0\ 0\ 0]

foreach value of numlist 1/3{
	mat stars`value'_temp = stars`value', zeros, zeros
}


mat outcomes = twfe1, twfe2, twfe3
mat stars = stars1_temp, stars2_temp, stars3_temp


frmttable using "tables/BorusyakLagged_c6elem.tex", replace tex statmat(outcomes) substat(3) sdec(0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","Low-Achieving", "Middle-Achieving", "High-Achieving" \ "" , "(1)", "(2)", "(3)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N") fragment
	
	
	
*** C6 Middle ***

*** Low-Score Students  group == 0 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if middle == 1

gen group = g_overall
keep if group == 0

* sample selection
foreach outcome of global outcomes{
	reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}



*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

}


mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Middle-Score Students  group == 1 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if middle == 1

gen group = g_overall
keep if group == 1


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}

*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id) pretrends(4)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout



*** High-Score Students group == 2 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if middle == 1

gen group = g_overall
keep if group == 2


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)
mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


mat zeros = [0\ 0\ 0\ 0\ 0]

foreach value of numlist 1/3{
	mat stars`value'_temp = stars`value', zeros, zeros
}


mat outcomes = twfe1, twfe2, twfe3
mat stars = stars1_temp, stars2_temp, stars3_temp


frmttable using "tables/BorusyakLagged_c6middle.tex", replace tex statmat(outcomes) substat(3) sdec(0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","Low-Achieving", "Middle-Achieving", "High-Achieving" \ "" , "(1)", "(2)", "(3)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N") fragment	
	

	
*** C6 High School ***

*** Low-Score Students  group == 0 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if highschool == 1

gen group = g_overall
keep if group == 0

* sample selection
foreach outcome of global outcomes{
	reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}



*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

}


mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


*** Middle-Score Students  group == 1 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if highschool == 1

gen group = g_overall
keep if group == 1


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}

*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id) pretrends(4)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout



*** High-Score Students group == 2 ***
use "$data/main.dta"", clear
drop if concept6_school == 0 & ever_treated == 1 | school_id == 196
keep if highschool == 1

gen group = g_overall
keep if group == 2


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
	qui did_imputation `outcome' school_id year yearChange if twfeS_`outcome' == 1, autosample fe(school_id year#grade) controls($controls3) nose
	
	gen sample_`outcome' = e(sample)
	tab sample_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes{
	
did_imputation `outcome' school_id year yearChange if sample_`outcome' == 1, autosample fe(school_id grade#year) controls($controls3) tol(.0001) maxit(10000) cluster(school_id)
mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


mat zeros = [0\ 0\ 0\ 0\ 0]

foreach value of numlist 1/3{
	mat stars`value'_temp = stars`value', zeros, zeros
}


mat outcomes = twfe1, twfe2, twfe3
mat stars = stars1_temp, stars2_temp, stars3_temp


frmttable using "tables/BorusyakLagged_c6highschool.tex", replace tex statmat(outcomes) substat(3) sdec(0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","Low-Achieving", "Middle-Achieving", "High-Achieving" \ "" , "(1)", "(2)", "(3)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N") fragment	
	

	
*---------------------------------------------------------
* * Tables A.11: Accounting for potential heterogeneous treatment effects for teacher turnover (Borusyak)
*---------------------------------------------------------
*** 90-30 Calendars ***
use "$main/teacher.dta", clear
drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes_teacher{
	
did_imputation `outcome' school_id year yearChange if sampleFE_`outcome' == 1, autosample fe(school_id grade#year) controls($controlsTeacher3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

}


mat stars1 = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe1 = twfeleftschool \ twfeinexp_leave \ twfeexp_leave


*** Concept 6 Calendars ***
use "$main/teacher.dta", clear
drop if concept6_school == 0 & ever_treated == 1


* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}


*** Add Lagged Controls ***
	
foreach outcome of global outcomes_teacher{
	
did_imputation `outcome' school_id year yearChange if sampleFE_`outcome' == 1, autosample fe(school_id grade#year) controls($controlsTeacher3) tol(.0001) maxit(10000) cluster(school_id)

mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe2 = twfeleftschool \ twfeinexp_leave \ twfeexp_leave



*** Elementary Schools ***
use "$main/teacher.dta", clear
drop if concept6_school == 0 & ever_treated == 1
keep if elem == 1


* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}

*** Add Lagged Controls ***
foreach outcome of global outcomes_teacher{
	
did_imputation `outcome' school_id year yearChange if sampleFE_`outcome' == 1, autosample fe(school_id grade#year) controls($controlsTeacher3) tol(.0001) maxit(10000) cluster(school_id)


matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars3 = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe3 = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

	
*** Middle Schools ***
use "$main/teacher.dta", clear
drop if concept6_school == 0 & ever_treated == 1
keep if middle == 1

* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}

*** Add Lagged Controls ***
foreach outcome of global outcomes_teacher{
	
did_imputation `outcome' school_id year yearChange if sampleFE_`outcome' == 1, autosample fe(school_id grade#year) controls($controlsTeacher3) tol(.0001) maxit(10000) cluster(school_id)


mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars4 = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe4 = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

*** High Schools ***
use "$main/teacher.dta", clear
drop if concept6_school == 0 & ever_treated == 1
keep if highschool == 1

* sample selection
foreach outcome of global outcomes_teacher{
	qui reghdfe `outcome' trad $controlsTeacher3 , ///
		absorb(grade_by_year school_id) cluster(school_id)
	gen sampleFE_`outcome' = e(sample)
	tab sampleFE_`outcome'
}


*** Add Lagged Controls ***
foreach outcome of global outcomes_teacher{
	
did_imputation `outcome' school_id year yearChange if sampleFE_`outcome' == 1, autosample fe(school_id grade#year) controls($controlsTeacher3) tol(.0001) maxit(10000) cluster(school_id)


mat list e(Nt)

matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars5 = starsleftschool \ starsinexp_leave \ starsexp_leave
mat twfe5 = twfeleftschool \ twfeinexp_leave \ twfeexp_leave

matrix starsBlank = J(3,2,0)
mat stars = stars1, starsBlank, stars2, starsBlank, stars3, starsBlank, stars4, starsBlank, stars5, starsBlank
mat outcomes = twfe1, twfe2, twfe3, twfe4, twfe5



frmttable using "tables/BorusyakLagged_teachers.tex", replace tex statmat(outcomes) substat(3) sdec(0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{1}{c}{90-30 Calendar}", "\multicolumn{4}{c}{Concept 6 Calendar}" \ "\cmidrule(lr){2-2} \cmidrule(lr){3-6}" "Elementary Schools", "All Schools", "Elementary Schools", "Middle Schools", "High Schools" \ "" , "(1)", "(2)", "(3)", "(4)", "(5)") ///
	rtitle("\textbf{A.Teacher Turnover}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Teachers with 0-2 Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Teachers with 3+ Years of Experience}"\"Transition to Traditional Calendar"\""\"N"\"R2") fragment




*---------------------------------------------------------
* Table A.12, A.13: Heterogeneous effects by student population changes
*---------------------------------------------------------
use "$data/main.dta"", clear

collapse (mean) member, by(elem middle highschool school_id year yearChange)


gen tracks = 1 if yearChange == .
replace tracks = 2 if yearChange > year & highschool == 1 & yearChange != .
replace tracks = 1 if yearChange <= year & highschool == 1 & yearChange != .

gen peers = member/tracks


gen beforeYearP = peers if year == yearChange - 1
gen afterYearP = peers if year == yearChange

bysort school_id: egen beforeChangePeer = min(beforeYearP)
bysort school_id: egen afterChangePeer = min(afterYearP)

gen changeStudentPeer = (afterChangePeer - beforeChangePeer)/beforeChangePeer
gen changeStudentPeer2 = changeStudentPeer




gen beforeYear = member if year == yearChange - 1
gen afterYear = member if year == yearChange



bysort school_id: egen beforeChangePop = min(beforeYear)
bysort school_id: egen afterChangePop = min(afterYear)

gen changeStudentPop = -(afterChangePop - beforeChangePop)/beforeChangePop
gen changeStudentPop2 = changeStudentPop




*** To get median values
preserve
bysort school_id: gen first = _n
keep if first == 1

sum changeStudentPop [aw = member] if elem == 1, d
sum changeStudentPop [aw = member] if middle == 1, d
sum changeStudentPop [aw = member] if highschool == 1, d

egen medianElem = median(changeStudentPop) if elem == 1
egen medianMid = median(changeStudentPop) if middle == 1
egen medianHS = median(changeStudentPop) if highschool == 1

egen medianpeers = median(changeStudentPeer) if highschool == 1

gen median = medianElem
replace median = medianMid if median == . 
replace median = medianHS if median == . 


tab median 
// elem median = 0.05806
// middle median = .154588
// highschool median = .2374696

tab medianpeers
//  percent change in peers -.6702501

restore


* Approach 1: replace always traditional schools to have 0 as changeStudentPop
replace changeStudentPop = 0 if yearChange == .

gen aboveMedianChange = (changeStudentPop >= .05806 & elem == 1)
replace aboveMedianChange = 1 if  (changeStudentPop >= .154588 & middle == 1)
replace aboveMedianChange = 1 if  (changeStudentPop >= .2374696 & highschool == 1)



* Approach 2: take the average change between years for always traditional schools
bysort school_id (year): gen twoYearChange = -(member[_n] - member[_n-1])/member[_n-1]
bysort school_id: egen avgTwoYearChange = mean(twoYearChange)

replace changeStudentPop2 = avgTwoYearChange if yearChange == . 


gen aboveMedianChange2 = (changeStudentPop2 >= .05806 & elem == 1)
replace aboveMedianChange2 = 1 if  (changeStudentPop2 >= .154588 & middle == 1)
replace aboveMedianChange2 = 1 if  (changeStudentPop2 >= .2374696 & highschool == 1)

// Median percent decrease in student population after calendar change: .0713407 (For only schools that changed calendar types)




drop beforeYear afterYear beforeChangePop afterChangePop member yearChange twoYearChange year elem middle highschool

duplicates drop 

histogram changeStudentPop2, frac
graph export "figures/changeInStudentPop.pdf", replace


histogram changeStudentPop2 if changeStudentPop != 0, frac
graph export "figures/changeInStudentPop_CalendarChangeSchools.pdf", replace

gen above = (aboveMedianChange == 1 | changeStudentPop == 0)
gen below = aboveMedianChange == 0

tempfile studentPop
save `studentPop', replace


foreach medianType in above below{

*** Merge data to main data
*** 90-30 Calendars ***
use "$data/main.dta"", clear
merge m:1 school_id using `studentPop'

drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1
keep if `medianType' == 1

* sample selection
foreach outcome of global outcomes{
	reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
}



*** Add Student Fixed ***
foreach outcome of global outcomes{
	
reghdfe `outcome' trad $controls4 if twfeS_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)


matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

}


mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade


*** Concept 6 Calendars ***
use "$data/main.dta"", clear
merge m:1 school_id using `studentPop'


drop if concept6_school == 0 & ever_treated == 1
keep if `medianType' == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
}



*** Add Student Fixed ***
foreach outcome of global outcomes{
	
reghdfe `outcome' trad $controls4 if twfeS_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)


matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade 



*** Elementary Schools ***
use "$data/main.dta"", clear
merge m:1 school_id using `studentPop'


drop if concept6_school == 0 & ever_treated == 1
keep if elem == 1
keep if `medianType' == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
}



*** Add Student Fixed ***
foreach outcome of global outcomes{
	
reghdfe `outcome' trad $controls4 if twfeS_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)


matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade 
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade 



*** Middle Schools ***
use "$data/main.dta"", clear
merge m:1 school_id using `studentPop'


drop if concept6_school == 0 & ever_treated == 1
keep if middle == 1
keep if `medianType' == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
}



*** Add Student Fixed ***
foreach outcome of global outcomes{
	
reghdfe `outcome' trad $controls4 if twfeS_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)


matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars4 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade 
mat twfe4 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade
		
*** High Schools ***
use "$data/main.dta"", clear
merge m:1 school_id using `studentPop'


drop if concept6_school == 0 & ever_treated == 1
keep if highschool == 1
keep if `medianType' == 1


* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen twfeS_`outcome' = e(sample)
	
}



*** Add Student Fixed ***
foreach outcome of global outcomes{
	
reghdfe `outcome' trad $controls4 if twfeS_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)


matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars5 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade 
mat twfe5 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade 
mat list twfe5

matrix starsBlank = J(4,2,0)
mat stars = stars1, starsBlank, stars2, starsBlank, stars3, starsBlank, stars4, starsBlank, stars5, starsBlank
mat outcomes = twfe1, twfe2, twfe3, twfe4, twfe5


frmttable using "tables/`medianType'MedianOverCrowding.tex", replace tex statmat(outcomes) substat(3) sdec(0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0\0\3\3\0) annotate(stars) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{1}{c}{90-30 Calendar}", "\multicolumn{4}{c}{Concept 6 Calendar}" \ "\cmidrule(lr){2-2} \cmidrule(lr){3-6}" "Elementary Schools", "All Schools", "Elementary Schools", "Middle Schools", "High Schools" \ "" , "(1)", "(2)", "(3)", "(4)", "(5)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N") fragment

}


foreach table in belowMedianOverCrowding aboveMedianOverCrowding{

filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSbegin{tabular}{lccccc}") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("&  &  &") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/`table'.tex" "tables/`table'1.tex", from("\BSend{center}") to("") replace
filefilter "tables/`table'1.tex" "tables/`table'.tex", from("\BSbegin{footnotesize}") to("") replace


erase "tables/`table'1.tex"

}


*---------------------------------------------------------
* Table A.14: Main estimates using Late Switchers as Control Group (90-30 Calendars)
*---------------------------------------------------------
*** 90-30 Calendars ***
use "$data/main.dta"", clear

drop if concept6_school == 1 & ever_treated == 1 | school_id == 196
keep if elem == 1

* sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls3 if group == 0, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	tab samplelag_`outcome'
	
	gen sampleFE_`outcome' = e(sample)
}



mat means9030 = .
foreach var in zcstmath zcstela absent_frac repeat_grade dropout{
	sum `var' if sampleFE_`var' == 1
	mat means9030 = means9030 \ r(mean)
}



*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome', sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_9030only.tex", replace tex statmat(twfe1) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars1) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{Elementary Schools}" \ "\cmidrule(lr){2-4}" , "(1)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") 

	

*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'

matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_9030only.tex", merge tex statmat(twfe2) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars2) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(2)")  rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "")


*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_9030only.tex", merge tex statmat(twfe3) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars3) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(3)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X")



	
	
*---------------------------------------------------------
* Table A.15: Main estimates using Late Switchers as Control Group (C6 Calendars)
*---------------------------------------------------------

*** Elementary Schools ***
use "$data/main.dta"", clear
keep if concept6_school == 1
keep if elem == 1

* Sample selection
foreach outcome of global outcomes{
	 qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	gen sampleFE_`outcome' = e(sample)

}

*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars1 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe1 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout

// matrix list stars

frmttable using "tables/twfe_byschooltype_c6Only.tex", replace tex statmat(twfe1) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars1) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{Elementary Schools}" \ "\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}" , "(1)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment
	
*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars2 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe2 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_c6Only.tex", merge tex statmat(twfe2) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars2) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{Middle Schools}" \ "" , "(2)")  rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars3 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe3 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_c6Only.tex", merge tex statmat(twfe3) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars3) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","\multicolumn{3}{c}{High Schools}" \ "" , "(3)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment
	


	
*** Middle Schools ***
use "$data/main.dta"", clear
keep if concept6_school == 1
keep if middle == 1


* Sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	gen sampleFE_`outcome' = e(sample)

}

*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars4 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe4 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_c6Only.tex", merge tex statmat(twfe4) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars4) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(4)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment


*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars5 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe5 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_c6Only.tex", merge tex statmat(twfe5) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars5) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(5)")  rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment

*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars6 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe6 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_c6Only.tex", merge tex statmat(twfe6) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars6) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(6)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment

		
*** High Schools ***
use "$data/main.dta"", clear
keep if concept6_school == 1
keep if highschool == 1

* Sample selection
foreach outcome of global outcomes{
	qui reghdfe `outcome' trad $controls2 $controls3, ///
		absorb(grade_by_year school_id student_id) cluster(school_id)
		
	gen samplelag_`outcome' = e(sample)
	gen sampleFE_`outcome' = e(sample)

}

*** Add Lagged Test Scores ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls2 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars7 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe7 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_c6Only.tex", merge tex statmat(twfe7) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars7) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(7)") rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", ""  \ "Student FE", "") ///
	fragment
	

*** Add Lagged Controls ***
foreach outcome of global outcomes{

reghdfe `outcome' trad $controls3 if samplelag_`outcome' == 1, ///
	absorb(grade_by_year school_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

mat stars8 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe8 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_c6Only.tex", merge tex statmat(twfe8) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars8) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(8)")  rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "X" \ "Lagged Non-Test Score Controls", "X" \ "Peer Controls", "X"  \ "Time-Varying School Controls", "X"  \ "Student FE", "") ///
	fragment


*** Add Student Fixed Effects ***
foreach outcome of global outcomes{

if "`outcome'" != "dropout"{
reghdfe `outcome' trad $controls4 if sampleFE_`outcome' == 1, ///
	absorb(grade_by_year school_id student_id) cluster(school_id)
			
matrix coef = e(b)
matrix se = e(V)
matrix obs = e(N)
matrix r2 = e(r2)
mat title = J(1,1,.)
mat twfe`outcome' = coef[1,1]
mat twfe`outcome' = title, twfe`outcome',sqrt(se[1,1]), obs, r2
mat list twfe`outcome'


matrix table = r(table)
matrix pvalue = table[4,1]
local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

forvalues k = 1/`bc' {
	matrix stars`outcome'[`k',2] = (pvalue[1,1] < .1) + (pvalue[1,1] < .05) + (pvalue[1,1] < .01)
}

mat list stars`outcome'

}

if "`outcome'" == "dropout"{

mat twfe`outcome' = J(1,5,.)
mat list twfe`outcome'

local bc = rowsof(twfe`outcome')
matrix stars`outcome' = J(`bc',2,0)

mat list stars`outcome'

}

}

mat stars9 = starszcstmath \ starszcstela \ starsabsent_frac \ starsrepeat_grade \ starsdropout
mat twfe9 = twfezcstmath \ twfezcstela \ twfeabsent_frac \ twferepeat_grade \ twfedropout


frmttable using "tables/twfe_byschooltype_c6Only.tex", merge tex statmat(twfe9) substat(4) sdec(0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3\0\3\3\0\3) annotate(stars9) ///
	brackets("","" \ "",""  \ (,) \ "","" \ "","" \ |,|) asymbol(*,**, ***) ///
	sfmt(fc) ctitle("","" \ "" , "(9)") ///
	rtitle("\textbf{A. Standardized Math Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{B. Standardized English Scores}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{C. Fraction of Days Absent}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{D. Grade is Repeated}"\"Transition to Traditional Calendar"\""\"N"\"R2"\"\textbf{E. Drops Out of High School}"\"Transition to Traditional Calendar"\""\"N"\"R2") ///
	addrows("" \ "Grade $\times$ Year FE", "X"  \ "School FE", "X" \ "Lagged Test Scores", "" \ "Lagged Non-Test Score Controls", "" \ "Peer Controls", ""  \ "Time-Varying School Controls", "X"  \ "Student FE", "X") ///
	fragment
	

filefilter "tables/twfe_byschooltype.tex" "tables/twfe_byschooltype1.tex", from("\BSbegin{center}") to("") replace
filefilter "tables/twfe_byschooltype1.tex" "tables/twfe_byschooltype.tex", from("\BSbegin{tabular}{lccccccccc}") to("") replace
filefilter "tables/twfe_byschooltype.tex" "tables/twfe_byschooltype1.tex", from("\BShline \BSnoalign{\BSsmallskip} ") to("") replace
filefilter "tables/twfe_byschooltype1.tex" "tables/twfe_byschooltype.tex", from("\BSnoalign{\BSsmallskip}\BShline\BSend{tabular}\BS\BS") to("") replace
filefilter "tables/twfe_byschooltype.tex" "tables/twfe_byschooltype1.tex", from("\BSend{center}") to("") replace
filefilter "tables/twfe_byschooltype1.tex" "tables/twfe_byschooltype.tex", from("\BSbegin{footnotesize}") to("") replace
filefilter "tables/twfe_byschooltype.tex" "tables/twfe_byschooltype1.tex", from("\BSend{footnotesize}") to("") replace
filefilter "tables/twfe_byschooltype1.tex" "tables/twfe_byschooltype.tex", from(" &  &  &  &  &  & ") to("") replace

erase "tables/twfe_byschooltype1.tex"





